-
Notifications
You must be signed in to change notification settings - Fork 0
Support type narrowing for non-callable node #136
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -350,11 +350,14 @@ const getCalleeDeclaration = (services, node) => { | |||||||||||
const calleeNode = getCallee(node); | ||||||||||||
if (!calleeNode) return null; | ||||||||||||
|
||||||||||||
const symbol = services | ||||||||||||
.getTypeAtLocation(calleeNode) | ||||||||||||
.symbol; | ||||||||||||
const type = services.getTypeAtLocation(calleeNode); | ||||||||||||
|
||||||||||||
if (!symbol || !symbol.valueDeclaration) { | ||||||||||||
if (type.symbol?.valueDeclaration) { | ||||||||||||
declaration = type.symbol.valueDeclaration; | ||||||||||||
} else if (type.symbol?.declarations?.length) { | ||||||||||||
// If there are multiple declarations, we take the first one. | ||||||||||||
declaration = type.symbol.declarations[0]; | ||||||||||||
Comment on lines
+358
to
+359
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Although you guard for
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||
} else { | ||||||||||||
const declarations = services | ||||||||||||
.getSymbolAtLocation(calleeNode) | ||||||||||||
?.declarations; | ||||||||||||
|
@@ -363,8 +366,6 @@ const getCalleeDeclaration = (services, node) => { | |||||||||||
|
||||||||||||
// If there are multiple declarations, we take the first one. | ||||||||||||
declaration = declarations[0]; | ||||||||||||
} else { | ||||||||||||
declaration = symbol.valueDeclaration; | ||||||||||||
} | ||||||||||||
} | ||||||||||||
if (!declaration) return null; | ||||||||||||
|
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.
[nitpick] Generator-like checks only run when the declaration is in
tsNodeToESTreeNodeMap
. If the signature isn’t mapped there, generator return types won’t be skipped. Consider obtaining the signature unconditionally or adjusting the guard.Copilot uses AI. Check for mistakes.