microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.03k stars 12.49k forks source link

Why Window.print() is removed? #22917

Closed Delagen closed 6 years ago

Delagen commented 6 years ago

TypeScript Version: 2.8.1

Search Terms:

Code

window.print()

Expected behavior: No errors.

Actual behavior: TypeScript error missing property print in Window

Playground Link: https://www.typescriptlang.org/play/index.html#src=window.print() Related Issues:

Delagen commented 6 years ago

Commit with changes 67c7b368e6dd2b5980ea9eafa9b0944459e4eb09

forestmaxime commented 6 years ago

Issue is present in 2.8.0 also. The commit also removes functions that exists in standard. It would be a good idea to redo a full code review on this one.

mhegazy commented 6 years ago

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

Delagen commented 6 years ago

git under windows produces unpredictable amount of changes, sorry for so many commits. I need to strip changelog to single line

Delagen commented 6 years ago

Thanks. Sorry I don,t read carefully instriction, that describe separate process for 2 files

evil-shrike commented 6 years ago

Also methods onbeforeprint and onafterprint were moved from Window into WindowEventHandlers which isn't related to Window. So it's a breaking change in 2.8. Code

    window.onbeforeprint = beforePrint;
    window.onafterprint = afterPrint;

start failing to compile: (533,11): error TS2339: Property 'onbeforeprint' does not exist on type 'Window'.
(534,11): error TS2339: Property 'onafterprint' does not exist on type 'Window'.
Please move them back into Window.

mhegazy commented 6 years ago

@evil-shrike please file a new ticket for that one and will get it fixed.

evil-shrike commented 6 years ago

23149

Kurtz1993 commented 6 years ago

Issue is still present in TypeScript 2.8.1

image

I use my worskpace TypeScript version which is 2.8.1 instead of VS Code's version (2.7.2).

mhegazy commented 6 years ago

Issue is still present in TypeScript 2.8.1

yes. the fix is scheduled to be released in 2.8.2

Kurtz1993 commented 6 years ago

Thanks @mhegazy !

mangeshdesai26 commented 6 years ago

Thanks @mhegazy

Delagen commented 6 years ago

@ps04639 You are wrong If you think that author of issue does not read TS docs

simonprice33 commented 6 years ago

(window as any).print(); looks to get around the issue but is still not great as when it creates the js file it resolves to window.print()

I am working on the latest available TypeScript via Nuget and the issue is still present today

Delagen commented 6 years ago

@simonprice33 What wrong in you answer, and what you expect?

DevEddy1 commented 6 years ago

@simonprice33 I believe at the time of posting this, the latest TS version is 2.8.3. If you are using VSCode (currently ships/updates with 2.8.1) - you can update the TS version to the latest with the command "npm install -g typescript@2.8.3". Follow the voted answer here for more information: Stack Overflow - TS Version

JaSpr commented 6 years ago

I'm using ts 2.9.1 and still getting this error.

Edit: Intellij is using 2.8.1 internally, which is causing the error. I don't see any way to change which version of typescript it is using internally. I've even told it to use the typescript under node_modules (which is 2.9.1) but the tab on IntelliJ still says "TypeScript 2.8.1".

That said, I am NOT having this issue in 2.9.1

ChamilaMaddumage commented 5 years ago

I am using this code snippet to print my PowerBI embedded report using Angular7 and getting following error.

let report = powerbi.get(reportContainer);

//Trigger the print dialog for your browser. report .print() .then(function (result) { console.log(result); }) .catch(function (errors) { console.log(errors); });

Error : [ts] property 'print' does not exist on type 'Embed'

simonprice33 commented 5 years ago

@ChamilaMaddumage try (report as any).print() and see how you get on