Skip to content

Regression in nightly build use of this type? #12490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
myitcv opened this issue Nov 24, 2016 · 5 comments
Closed

Regression in nightly build use of this type? #12490

myitcv opened this issue Nov 24, 2016 · 5 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Milestone

Comments

@myitcv
Copy link

myitcv commented Nov 24, 2016

Easiest explained via the repro steps:

$ cd `mktemp -d`
$ npm init --force
$ npm install --save-dev [email protected]
$ grep -r 'onload:' node_modules/typescript/lib/
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: this, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: this, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: this, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: this, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: this, ev: Event) => any;
....

But then

$ npm install --save-dev [email protected]
$ grep -r 'onload:' node_modules/typescript/lib/
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: Document, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: HTMLBodyElement, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: HTMLElement, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: HTMLFrameElement, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: HTMLFrameSetElement, ev: Event) => any;
node_modules/typescript/lib/lib.es6.d.ts:    onload: (this: HTMLIFrameElement, ev: Event) => any;
...

This has the obvious impact:

let image = new Image();

// with [email protected]
image.onload // has type HTMLElement.onload: (this: HTMLImageElement, ev: Event) => any

// with [email protected]
image.onload // has type HTMLElement.onload: (this: HTMLElement, ev: Event) => any

Is this an intentional change?

@myitcv
Copy link
Author

myitcv commented Dec 1, 2016

@mhegazy et al - any thoughts on this?

@mhegazy mhegazy added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Dec 1, 2016
@mhegazy mhegazy self-assigned this Dec 1, 2016
@mhegazy mhegazy added this to the TypeScript 2.2 milestone Dec 12, 2016
@myitcv
Copy link
Author

myitcv commented Dec 19, 2016

@mhegazy I'd like to be able to get back to using the latest nightly, help to flush out issues on your side and ours. But because of this issue, the nightly build is broken from our perspective.

Do you have any indication on when this will be fixed?

Or are there bigger question that arise out of #12433 that need addressing/thinking about first?

Thanks

@mhegazy
Copy link
Contributor

mhegazy commented Dec 19, 2016

i need to update the script that generates the file in https://github.com/Microsoft/TSJS-lib-generator. I have not had a chance to do that. PRs are always welcomed.

@myitcv
Copy link
Author

myitcv commented Jan 24, 2017

@mhegazy this bug is present in the now released 2.1.4 and 2.1.5.

One thing I'm not clear on is why this isn't breaking for more people?

@Andarist
Copy link
Contributor

Andarist commented Jan 8, 2023

It's hard to tell if this was fixed or not - the DOM lib types have changed and this is typed as GlobalEventHandlers within onload's signature. So it seems that if one wants to access a more narrow type for this they should use addEventListener (and that works OK):

let image = new Image();

image.addEventListener('load', function () {
  this // HTMLImageElement
})

I think that the issue can be closed for housekeeping purposes, cc @RyanCavanaugh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants