feat(typescript-types): Add test for any and never in OptionalKeysOf

This commit is contained in:
T. R. Bernstein
2025-07-14 13:48:59 +02:00
parent 610e7a0518
commit a7bc60fa69
2 changed files with 8 additions and 3 deletions

View File

@@ -22,9 +22,11 @@ The types included in this library are categorized by their purpose.
#### Extraction Types
| Type | Description |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [`OptionalKeysOf<T>`][] | A union of all keys of `T` that are marked as optional. If `T` is a union, a union of the optional keys of all union members of `T` is returned. |
| Type | Description |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`OptionalKeysOf<T>`][] | A union of all keys of `T` that are marked as optional. If `T` is a union, a union of the optional keys of all union members of `T` is returned[^optional-keys-of_remark]. |
[^optional-keys-of_remark]: If `T` is `any`, it returns a union of string and number 'string | number'.
[`OptionalKeysOf<T>`]: src/optional-keys-of.ts

View File

@@ -31,6 +31,9 @@ expect<OptionalKeysOf<Example1 | Example2>>().type.toBe<
'optionalKey' | 'anotherOptional' | 'optionalKey2' | 'anotherOptional2'
>()
expect<OptionalKeysOf<any>>().type.toBe<string | number>()
expect<OptionalKeysOf<never>>().type.toBeAssignableWith<never>()
expect<Pick<Example1, OptionalKeysOf<Example1>>>().type.toBe<
ExpectKeyOf<Example1, OptionalKeysOf<Example1>>
>()