feat(typescript-types): Add isKeyOf<T,K>

This commit is contained in:
T. R. Bernstein
2025-07-14 15:39:53 +02:00
parent a7bc60fa69
commit bb706e7780
3 changed files with 42 additions and 5 deletions

View File

@@ -8,11 +8,12 @@ The types included in this library are categorized by their purpose.
#### Test Types
| Type | Description |
| --------------------------------------- | ------------------------------------------------------------------------------------------- |
| [`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`) |
| [`If<Test, TrueBranch, FalseBranch>`][] | Returns `TrueBranch` if `Test` is `true`, `FalseBranch` otherwise[^if_remark]. |
| Type | Description |
| --------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [`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`) |
| [`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`. |
[^if_remark]: If `boolean` is passed as `Test` the return value is a union of both branches, i.e. `TrueBranch | FalseBranch`.