feat(typescript-types): Add test for any and never in OptionalKeysOf
This commit is contained in:
@@ -23,8 +23,10 @@ The types included in this library are categorized by their purpose.
|
|||||||
#### Extraction Types
|
#### Extraction Types
|
||||||
|
|
||||||
| Type | Description |
|
| 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. |
|
| [`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
|
[`OptionalKeysOf<T>`]: src/optional-keys-of.ts
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ expect<OptionalKeysOf<Example1 | Example2>>().type.toBe<
|
|||||||
'optionalKey' | 'anotherOptional' | 'optionalKey2' | 'anotherOptional2'
|
'optionalKey' | 'anotherOptional' | 'optionalKey2' | 'anotherOptional2'
|
||||||
>()
|
>()
|
||||||
|
|
||||||
|
expect<OptionalKeysOf<any>>().type.toBe<string | number>()
|
||||||
|
expect<OptionalKeysOf<never>>().type.toBeAssignableWith<never>()
|
||||||
|
|
||||||
expect<Pick<Example1, OptionalKeysOf<Example1>>>().type.toBe<
|
expect<Pick<Example1, OptionalKeysOf<Example1>>>().type.toBe<
|
||||||
ExpectKeyOf<Example1, OptionalKeysOf<Example1>>
|
ExpectKeyOf<Example1, OptionalKeysOf<Example1>>
|
||||||
>()
|
>()
|
||||||
|
|||||||
Reference in New Issue
Block a user