Skip to content

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

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Dec 21, 2017

This replaces the best-effort aliasSymbol machinery we currently use with another property that allows printing keyof Alias<T> types instead of just Alias<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

Copy link
Member

@sandersn sandersn left a 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.


export const enum AliasKind {
None,
KeyOf
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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.

return createTypeReferenceNode(name, typeArgumentNodes);
const ref = createTypeReferenceNode(name, typeArgumentNodes);
if (type.aliasKind === AliasKind.KeyOf) {
return createTypeOperatorNode(ref);
Copy link
Member

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.

Copy link
Member Author

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 🤷‍♂️

@weswigham weswigham force-pushed the best-effort-keyof-alias-preservation branch from 5d1ce0c to caa358b Compare December 22, 2017 21:50
@weswigham
Copy link
Member Author

@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.

@typescript-bot
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants