-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Better completion for property access of computed properties #56220
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
base: main
Are you sure you want to change the base?
Conversation
…ranas/completion-computed-property
@typescript-bot pack this |
Hey @gabritto, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
node = typeChecker.symbolToEntityName(nameSymbol, /*meaning*/ undefined!, contextToken, NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope); | ||
} | ||
else { | ||
// Object literals assigned as const |
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.
What's this case for, exactly? I think I don't understand the comment here and how we know this from knowing that nameSymbol
is a transient symbol.
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 scenario goes into this branch:
const x = { a: "foo" } as const;
const y = { [x.a]: 0 };
y.|
It's because the symbol a
is associated with the object and not x
so walking up the parent symbols will just go to __object
- so symbolToEntityName
(the other branch) won't give a full access expression to it.
That being said, I don't know if isTransientSymbol
is the right check here - are there transient symbols that won't run into this issue? and are there non-transient symbols that will run into this issue? I can be safe an always choose the else
branch (get rid of the whole if
).
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'm not sure if all transient symbols run into this problem with symbolToEntityName
, but I think I was confused by the comment because it sorta implied that if the symbol is transient, then we have that object literal situation, which I think is not always the case.
@weswigham might know the details of symbolToEntityName
and symbolToExpression
.
Improvement suggestion: Example: // @filename: ex.ts
export type T = {
[Sym.sym]: number;
}
export namespace Sym {
export const sym = Symbol("unique!");
}
// @filename: index.ts
import { T } from "./ex";
declare const obj: T;
obj.| Since we don't have |
@@ -3124,6 +3125,15 @@ function getContextualType(previousToken: Node, position: number, sourceFile: So | |||
} | |||
} | |||
|
|||
/** | |||
* An accessible symbol is a local in the same block or any enclosing blocks, up to and including the global scope (note imports are global). |
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 don't know if this comment is 100% accurate, but this is my understanding of what this method does. Open to change this if it's wrong.
Improves completion to now show the qualified name of the completion.
If the user sets
includeCompletionsWithInsertText
to false, we will only use the literal completion for the property (x.a
andx.b
in the example above).Fixes #56096