Skip to content
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

Merged
merged 3 commits into from
Oct 22, 2021

Conversation

DanielRosenwasser
Copy link
Member

Fixes #46468

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Oct 21, 2021
Comment on lines +66 to +68
//// [a.d.ts]
declare class Thing {
}
Copy link
Member Author

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.

Comment on lines +70 to +72
constructor(arrayLength?: number);
constructor(arrayLength: number);
constructor(...items: any[]);
Copy link
Member Author

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.

Copy link
Member

@gabritto gabritto left a 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[]'.
Copy link
Member

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[]

Copy link
Member Author

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 😢

@DanielRosenwasser DanielRosenwasser merged commit 334b8ea into main Oct 22, 2021
@DanielRosenwasser DanielRosenwasser deleted the thisAssignmentInStaticBlock branch October 22, 2021 22:44
mprobst pushed a commit to mprobst/TypeScript that referenced this pull request Jan 10, 2022
…t#46472)

* Add failing test case.

* Handle 'this' assignments on class static blocks in JavaScript.

* Accepted baselines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
4 participants