-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Js constructor function fixes #22721
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
Conversation
Symbol-based now instead of syntactic
@@ -4259,7 +4259,12 @@ namespace ts { | |||
} | |||
|
|||
if (isPropertyAccessExpression(expression.left) && expression.left.expression.kind === SyntaxKind.ThisKeyword) { | |||
if (getThisContainer(expression, /*includeArrowFunctions*/ false).kind === SyntaxKind.Constructor) { | |||
const thisContainer = getThisContainer(expression, /*includeArrowFunctions*/ false); |
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.
An explanatory comment would be nice to have here
@@ -4259,7 +4259,14 @@ namespace ts { | |||
} | |||
|
|||
if (isPropertyAccessExpression(expression.left) && expression.left.expression.kind === SyntaxKind.ThisKeyword) { | |||
if (getThisContainer(expression, /*includeArrowFunctions*/ false).kind === SyntaxKind.Constructor) { | |||
const thisContainer = getThisContainer(expression, /*includeArrowFunctions*/ false); | |||
const isPrototypeProperty = isBinaryExpression(thisContainer.parent) && |
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.
Only used if thisContainer.kind === SyntaxKind.FunctionExpression
, might want to avoid computing this otherwise.
JS constructors had a couple of bugs with strictNullChecks (which people actually do use with checkJs, see the recent post by @OliverJAsh).
undefined
to the type of all properties:Incorrectly had
x: number | undefined
notx: number
.This incorrectly had
a: { x: number } | undefined
when it should have beena: { x: number }
Fixes #22414
Fixes #22641
Note that the second fix checks two things to distinguish a constructor function from a normal one:
return new A()
somewhere insidefunction A
. It doesn't check whether this statement is inside a conditional.