Skip to content
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a625258
Add `UnionToEnum` type and corresponding tests, and docs
benzaria Jun 7, 2025
c338ab4
Update example in `UnionToEnum` type to use more descriptive keys
benzaria Jun 7, 2025
a910dcb
Improve documentation for UnionToEnumOptions and related types
benzaria Jun 7, 2025
02f1a93
Add 'as const' to tests for `readonly` keyword
benzaria Jun 7, 2025
ef81023
feat: remove case transformation
benzaria Jun 9, 2025
ed6350d
Merge branch 'main' into UnionToEnum
benzaria Jun 9, 2025
767dbf9
Merge branch 'main' into UnionToEnum
benzaria Jun 10, 2025
40e029f
doc: add description in `readme`
benzaria Jun 10, 2025
e763095
doc: sanitize JsDoc & description
benzaria Jun 10, 2025
d54d526
feat: add extra Edge cases in tests
benzaria Jun 10, 2025
030ce52
feat: move `Numeric` to options, improve options JsDoc & add new egde…
benzaria Jun 11, 2025
eb8b785
Merge branch 'main' into UnionToEnum
benzaria Jun 18, 2025
e603f66
Merge branch 'main' into UnionToEnum
benzaria Sep 23, 2025
2471aef
Update union-to-enum.d.ts
sindresorhus Sep 27, 2025
b733afd
update docs
benzaria Sep 27, 2025
ba20563
Merge branch 'main' into UnionToEnum
benzaria Sep 27, 2025
d64d391
add `export {}` to EOL
benzaria Sep 27, 2025
dae00cf
Merge branch 'main' into UnionToEnum
benzaria Oct 9, 2025
7167d17
Update union-to-enum.d.ts
sindresorhus Oct 10, 2025
c7bad80
add more tests
benzaria Oct 19, 2025
7efbf20
fix: eliminate the possibility of passing a union and tuple keys at t…
benzaria Oct 20, 2025
bc8d651
Merge branch 'origin/UnionToEnum' into UnionToEnum
benzaria Oct 21, 2025
fcc9a08
docs: fix JsDoc examples
benzaria Oct 21, 2025
151e08b
add some test covering changes
benzaria Oct 22, 2025
6581e5d
fix: output is not assainable to `T[]`
benzaria Nov 6, 2025
dbc8fab
feat: split `UnionToEnum` into 2 types
benzaria Nov 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: eliminate the possibility of passing a union and tuple keys at t…
…he same time
  • Loading branch information
benzaria committed Oct 21, 2025
commit 7efbf2066a1510ef40755d3615ab63d132f4ab43
8 changes: 6 additions & 2 deletions source/union-to-enum.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type UnionToEnumOptions = {

@example
```
type E2 = UnionToEnum<['Play', 'Pause', 'Stop'], {numeric: true}>;
type E1 = UnionToEnum<['Play', 'Pause', 'Stop'], {numeric: true}>;
//=> { Play: 1; Pause: 2; Stop: 3 }

type E2 = UnionToEnum<['Play', 'Pause', 'Stop'], {numeric: true; startIndex: 3}>;
Expand Down Expand Up @@ -115,7 +115,11 @@ const Template = createEnum(verb, resource);
@category Object
*/
export type UnionToEnum<
Keys extends PropertyKey | readonly PropertyKey[],
Keys extends (
[Keys] extends [PropertyKey]
? PropertyKey
: readonly PropertyKey[]
),
Options extends UnionToEnumOptions = {},
> = IsNever<Keys> extends true ? {}
: _UnionToEnum<
Expand Down