Skip to content

Conversation

mi5ha
Copy link

@mi5ha mi5ha commented Oct 30, 2024

If LiteralUnion is defined like this:

export type LiteralUnion<T extends U, U = string> = T | (U & {});

It will make these have string type:

EvaStatus
EvaSize
EvaInputSize

So information about union is lost.

This is possible fix:

export type LiteralUnion<T extends U, U = string> = T | (string & {});

Now EvaSize and other will be of proper union type, and they will also allow custom string.

This fix will also make autocomplete possible for those props.

*/
// eslint-disable-next-line @typescript-eslint/ban-types
export type LiteralUnion<T extends U, U = string> = T | (U & {});
export type LiteralUnion<T extends U, U = string> = T | (string & {});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @mi5ha,

This won't work in the case you wanna change U to number for example (there you should get a type error).
image

So I think changing this type to the following would be more correct, as you then get ts errors in the numbers case, while also receiving auto-completion hints.

type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);

image
image

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.

2 participants