-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Print unions resulting from keyof operations with keyof if possible #20838
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
Print unions resulting from keyof operations with keyof if possible #20838
Conversation
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.
Since this isn't a high-priority fix (I think), I'd like to see a more comprehensive fix, or at least better encapsulated. Otherwise I feel like we'll just keep adding extra optional properties to existing things.
src/compiler/types.ts
Outdated
|
||
export const enum AliasKind { | ||
None, | ||
KeyOf |
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 seems pretty ad-hoc right now. Could it apply to other dual-representation types? Do you plan to change those to use this system?
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.
Specifically, it seems like the existing aliasSymbol/aliasTypeArguments properties accomplish a similar thing, and would benefit from a general solution.
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 do have a design for a more general solution (two, actually). I'll update this PR with the more moderate of the two.
src/compiler/checker.ts
Outdated
return createTypeReferenceNode(name, typeArgumentNodes); | ||
const ref = createTypeReferenceNode(name, typeArgumentNodes); | ||
if (type.aliasKind === AliasKind.KeyOf) { | ||
return createTypeOperatorNode(ref); |
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.
a "TypeOperatorNode" is really a KeyofNode, isn't it? Would you be OK with changing the name? Doesn't have to be in this PR, just asking.
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.
unique
should also be a type operator node - the factory was just never updated to account for that, I think, since it's always just made as unique symbol
(so you'll never need anything else right now). So... the name should probably be changed 🤷♂️
5d1ce0c
to
caa358b
Compare
@sandersn I have a much more complete alternative representation implementation now; though it would be simpler if we'd removed the symbol display builder already. |
Thanks for your contribution. This PR has not been updated in a while and cannot be automatically merged at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to continue working on this PR, please leave a message and one of the maintainers can reopen it. |
This replaces the best-effort
aliasSymbol
machinery we currently use with another property that allows printingkeyof Alias<T>
types instead of justAlias<T>
types - in fact, it allows printing a type as any alternative representation you choose, so should be usable for other desirable aliases as well (perhaps indexed access types in the future).Fixes #17294