Skip to content
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

Make LiteralUnion type work for more types #97

Merged
merged 1 commit into from
Sep 29, 2020

Conversation

kripod
Copy link
Contributor

@kripod kripod commented Apr 10, 2020

While experimenting with automatic prop completion for an upcoming CSS-in-JS library, I wanted to use LiteralUnion as follows:

import { CSSProperties } from 'react';

enum Duration {
  SHORT = 1, // Gets resolved to a string somewhere else in the code
  LONG,
}

type AnimationDurationValue = LiteralUnion<
  Duration,
  CSSProperties['animationDuration']
>;

LiteralUnion works perfectly when LiteralType doesn't extend BaseType.

@sindresorhus
Copy link
Owner

// @BendingBender

@kripod
Copy link
Contributor Author

kripod commented Apr 19, 2020

I would like to ask for a status update on this. Thank you for reviewing in advance!

Until then, here is a real world use-case: https://github.com/kripod/glaze/blob/c363cf3986f595a2759fedb08030f88e40e6ad7b/packages/glaze/src/useStyling.ts#L82-L96

@sindresorhus
Copy link
Owner

I haven't had a chance to look into this yet. I'm thinking there must be a reason we did it like this in the first place. Maybe some more info in microsoft/TypeScript#29729.

Can you add a test that shows the use-case you need it for when it's not extending basetype?

@kripod
Copy link
Contributor Author

kripod commented Apr 26, 2020

Unfortunately, I don't have the capacity to set up a test right now, sorry.

@forivall
Copy link

forivall commented Sep 16, 2020

TypeScript 4.0 no longer needs LiteralUnion (it preserves the literals that are union'd with their base type), so this can probably be closed (and LiteralUnion can eventually be removed) Just double checked in the playground -- maybe not? I need to check their issues. I remember i tested in vscode a few days ago, and it appeared fixed.

@papb
Copy link
Contributor

papb commented Sep 16, 2020

@forivall I doubt that, since microsoft/TypeScript#29729 is still open...

@sindresorhus sindresorhus changed the title [LiteralUnion] LiteralType needn't extend BaseType Make LiteralType type work for more types Sep 29, 2020
@sindresorhus sindresorhus changed the title Make LiteralType type work for more types Make LiteralUnion type work for more types Sep 29, 2020
@sindresorhus sindresorhus changed the title Make LiteralUnion type work for more types Make LiteralUnion type work for more types Sep 29, 2020
@sindresorhus sindresorhus merged commit 37e2816 into sindresorhus:master Sep 29, 2020
@kripod kripod deleted the patch-1 branch September 30, 2020 05:18
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.

None yet

4 participants