feat(typescript-types): Make Assign assignable to Generics by removing optionals

This commit is contained in:
T. R. Bernstein
2025-07-15 12:00:02 +02:00
parent f7cde6388d
commit 4ec764de9e
7 changed files with 85 additions and 15 deletions

View File

@@ -24,6 +24,7 @@ The types included in this library are categorized by their purpose.
| --------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [`IsAny<T>`][] | `true` if `T` is `any`, `false` otherwise (`null`, `undefined` also yield `false`) |
| [`IsNever<T>`][] | `true` if `T` is `never`, `false` otherwise (`null`, `undefined`, `any` also yield `false`) |
| [`IsUndefined<T>`][] | `true` if `T` is `undefined`, `false` otherwise (`null`, `never`, `any` also yield `false`). |
| [`If<Test, TrueBranch, FalseBranch>`][] | Returns `TrueBranch` if `Test` is `true`, `FalseBranch` otherwise[^if_remark]. |
| [`IsKeyOf<T, K>`][] | `true` if `K` is a key of `T`, `false` otherwise. If `T` is `any`, any `K` but `never` will yield `true`. |
| [`IsEmptyString<S>`][] | `true` if `S` is the empty string `''`, `false` otherwise.[^is-empty-string_remark] |
@@ -34,19 +35,22 @@ The types included in this library are categorized by their purpose.
[`IsAny<T>`]: src/is-any.ts
[`IsNever<T>`]: src/is-never.ts
[`IsUndefined<T>`]: src/is-undefined.ts
[`If<Test, TrueBranch, FalseBranch>`]: src/if.ts
[`IsKeyOf<T, K>`]: src/is-key-of.ts
[`IsEmptyString<S>`]: src/is-empty-string.ts
#### 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[^optional-keys-of_remark]. |
| 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]. |
| [`PickAssignable<T, K>`][] | Return a mapped type with all keys of `T` that extend `K`. If no key does extend `K` an empty type is returned. |
[^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
[`PickAssignable<T, K>`]: src/pick-assignable.ts
#### Conversion Types