-
-
Notifications
You must be signed in to change notification settings - Fork 610
Add UnionToEnum
type
#1171
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?
Add UnionToEnum
type
#1171
Conversation
@som-sm @sindresorhus Should CamelCase be |
This type is doing too much. It should not do case transformation. That would be a task for a separate type. It should purely transform union to enum. |
fair enough i will remove case transformation. |
I don't think it should do startingIndex either. It's too limiting and could be done by a separate type too. |
Should I keep the starting index |
Hmm, didn't think of that. Maybe we do indeed need the |
True, diff users may want diff index for there enum. |
@sindresorhus @som-sm Ready ! |
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 should be the behaviour in cases where UnionToEnum
returns an index signature?
For example, currently invalid index signatures are returned in cases like these:
type T1 = UnionToEnum<string | number>;
// {readonly [x: string]: string; readonly [x: number]: number}
type T2 = UnionToEnum<[string, 'foo'], true>;
// {readonly [x: string]: 1; readonly foo: 2}
Maybe we should skip all non-literals?
Should also skip |
Closes #1084
Add
UnionToEnum<T, Numeric, Options>
utility for converting a union/tuple into an Enum-like object.string
,number
, orsymbol
unions or tuples1
Example: