-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Change "isThisless" predicates to "mayReferenceThis" predicates #20036
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
Why would we change this? |
It's easier to think about, "a function references this if some parameter does", than "a function is this-less if there isn't any non-this-less parameter". |
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.
I would use the naming scheme xxxReferencesThis
because at some point we may make this code more complete.
src/compiler/checker.ts
Outdated
case SyntaxKind.Constructor: { | ||
// A function-like declaration references `this` if its return type does or some parameter / type parameter does. | ||
const fn = declaration as MethodDeclaration | MethodSignature | ConstructorDeclaration; | ||
return (declaration.kind !== SyntaxKind.Constructor && typeMayReferenceThis(getEffectiveReturnTypeNode(fn))) |
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.
if getEffectiveReturnTypeNode
returns undefined
for nodes with SyntaxKind.Constructor
, then you can skip the kind check here.
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.
src/compiler/checker.ts
Outdated
/** A type parameter is thisless if its contraint is thisless, or if it has no constraint. */ | ||
function isThislessTypeParameter(node: TypeParameterDeclaration) { | ||
return !node.constraint || isThislessType(node.constraint); | ||
return true; |
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.
should probably reference #20034 here too, because there are plenty of type nodes that could be inspected for this
more closely.
Can we not merge this until we have actually discussed it? |
@Andy-MS @sandersn Please revert this back to the way it was. These functions were designed to return |
From code review on #19655