-
Notifications
You must be signed in to change notification settings - Fork 12.9k
For { type: "a" } | { type: "b" }
, find references for the union property
#21298
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/services/findAllReferences.ts
Outdated
@@ -415,7 +415,11 @@ namespace ts.FindAllReferences.Core { | |||
return checker.getImmediateAliasedSymbol(symbol); | |||
} | |||
|
|||
return symbol; | |||
// If the symbol is declared as part of a declaration like `{ type: "a" } | { type: "b" }`, use the property on the union type to get more references. | |||
return symbol.declarations && firstDefined(symbol.declarations, decl => |
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.
getReferencedSymbolsForSymbol instead of returning propertyOfUnion, shouldnt you be returning all properties of the constituents with that name as symbols from getReferencedSymbolsForSymbol
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 we use the property on the union as the search symbol, populateSearchSymbolSet
will call checker.getRootSymbols
to get the constituents of the union.
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.
Yeah makes sense.. Whats the reason to check if declaration is type node.. why not just check if the type at that location is union and return union property ?
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.
In: { type: "a" } | { type: "b" }
If we're doing find-all-references on the first type
, the declaration will be a PropertyDeclaration type: "a"
. The parent is a TypeLiteralNode { type: "a" }
and parent.parent is the whole thing.
We have to go at least to parent.parent
to get a union type node. If we make calls at any child of that we won't get a union type, but the nameless type for the node { type: "a" }
which is not a union, but a constituent of the union.
Waiting for approval from @sheetalkamat before merging. |
* origin/master: (134 commits) Fix isTypeOfExpression in compiler API (microsoft#20875). (microsoft#20884) add completion filter for function like body (microsoft#21257) Make nonnull assertions and binding patterns apparent declared type locations (microsoft#20995) For `{ type: "a" } | { type: "b" }`, find references for the union property (microsoft#21298) configureNightly -> configurePrerelease Create a 'configure-insiders' and 'publish-insiders' task. Add createProgram on WatchCompilerHost in goToDefinition, use array helpers and clean up code (microsoft#21304) Support testing definition range of a reference gruop (microsoft#21302) Handle `undefined` input to firstDefined (microsoft#21300) Avoid spreading array (microsoft#21291) LEGO: check in for master to temporary branch. Accept new baselines Add regression test Properly handle contravariant inferences in inferReverseMappedType Remove unused properties from interface Refactor (microsoft#21286) LEGO: check in for master to temporary branch. Fold newline logic into getNewLineOrDefaultFromHost External test runner updates (microsoft#21276) Report more detailed info during script debug failure ...
Fixes #21288
Discovered #21297
This will not fix the issue if it is written like:
That case is harder, because we would have to find all references to the containing type to find out if it is used as part of a union.