-
Notifications
You must be signed in to change notification settings - Fork 12.9k
A function should be context-sensitive if its return expression is #17697
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
src/compiler/checker.ts
Outdated
if (node.kind !== SyntaxKind.ArrowFunction) { | ||
// If the first parameter is not an explicit 'this' parameter, then the function has | ||
// an implicit 'this' parameter which is subject to contextual typing. Otherwise we | ||
// know that all parameters (including 'this') have type annotations and nothing is |
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.
Is this comment still accurate?
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.
"nothing is subject to contextual typing" should change to read "only the return type could still be subject to contextual typing".
src/compiler/checker.ts
Outdated
const parameter = firstOrUndefined(node.parameters); | ||
return !(parameter && parameterIsThisKeyword(parameter)); | ||
|
||
// TODO(anhans): A block should be context-sensitive if it has a context-sentitive return value. |
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.
typo:sensitive
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 a response to comment above this -- github won't let me respond to that for some reason.) I'll just remove the second half of this comment since it doesn't add much that isn't already clear from reading the function's code.
src/compiler/checker.ts
Outdated
if (node.kind !== SyntaxKind.ArrowFunction) { | ||
// If the first parameter is not an explicit 'this' parameter, then the function has | ||
// an implicit 'this' parameter which is subject to contextual typing. Otherwise we | ||
// know that all parameters (including 'this') have type annotations and nothing is |
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.
"nothing is subject to contextual typing" should change to read "only the return type could still be subject to contextual typing".
Can you address the merge conflicts? |
Fixes #17586
If we're going to do this, we should also consider caching this function, since it gets called a lot.