-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Bind assignments to 'this' within static blocks in JS files #46472
Conversation
//// [a.d.ts] | ||
declare class Thing { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong, but not something I would consider in scope for this PR. I will create a follow-up issue for doSomething
getting dropped in the .d.ts
output.
constructor(arrayLength?: number); | ||
constructor(arrayLength: number); | ||
constructor(...items: any[]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I don't know why this needs to be duplicated in the .d.ts
emit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎃
~~~~~~~~~~~~~ | ||
!!! error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: any): arg is any[]; readonly prototype: any[]; }'. | ||
!!! error TS2417: Types of property 'isArray' are incompatible. | ||
!!! error TS2417: Type '(arg: any) => boolean' is not assignable to type '(arg: any) => arg is any[]'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related to this PR, but I'm curious as to why this.isArray
ends up with type (arg: any) => boolean
instead of (arg: any) => arg is any[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't try to infer type predicate signatures - users always have to write them out deliberately, and can't rely on contextual types.
But even if we did rely on contextual types, we have another issue with class members not using them #23911 😢
…t#46472) * Add failing test case. * Handle 'this' assignments on class static blocks in JavaScript. * Accepted baselines.
Fixes #46468