Add UnionToEnum and TupleToEnum types and fix UnionToTuple output#1171
Add UnionToEnum and TupleToEnum types and fix UnionToTuple output#1171benzaria wants to merge 26 commits intosindresorhus:mainfrom
UnionToEnum and TupleToEnum types and fix UnionToTuple output#1171Conversation
|
@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.
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 |
15e3625 to
b733afd
Compare
|
Apologies, haven't been able to re-read this. I'll give it a read sometime next week. |
|
@som-sm, Hey 👋 just following up on this, you mentioned you’d review it next week, but I haven’t seen any updates yet. |
|
@som-sm Could you please take some time to review this PR when you get a chance, so we can move it forward? |
|
This type name and parameter make me confused, maybe it can be split to |
@Emiyaaaaa Yeah, pretty valid point, if the type is |
|
@som-sm I also have a suggestion, why not just call it |
Umm...no, |
UnionToEnum typeUnionToEnum and TupleToEnum types and fix UnionToTuple output

Closes #1084
Add
UnionToEnum<T, Numeric, Options>utility for converting a union/tuple into an Enum-like object.string,number, orsymbolunions or tuples1Example: