feat(typescript-types): Add IsEmptyKey<S>
This commit is contained in:
@@ -14,9 +14,12 @@ The types included in this library are categorized by their purpose.
|
||||
| [`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`. |
|
||||
| [`IsEmptyString<S>`][] | `true` if `S` is the empty string `''`, `false` otherwise.[^is-empty-string_remark] |
|
||||
|
||||
[^if_remark]: If `boolean` is passed as `Test` the return value is a union of both branches, i.e. `TrueBranch | FalseBranch`.
|
||||
|
||||
[^is-empty-string_remark]: If `T` is `any` will yield `true`, as it is taken to be `any` string.
|
||||
|
||||
[`IsAny<T>`]: src/is-any.ts
|
||||
[`IsNever<T>`]: src/is-never.ts
|
||||
[`If<Test, TrueBranch, FalseBranch>`]: src/if.ts
|
||||
|
||||
1
packages/typescript-types/src/is-empty-string.ts
Normal file
1
packages/typescript-types/src/is-empty-string.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type IsEmptyString<T extends string> = '' extends T ? true : false
|
||||
8
packages/typescript-types/test/is-empty-string.tst.ts
Normal file
8
packages/typescript-types/test/is-empty-string.tst.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { IsEmptyString } from '@/is-empty-string.js'
|
||||
import { expect } from 'tstyche'
|
||||
|
||||
expect<IsEmptyString<''>>().type.toBe<true>()
|
||||
expect<IsEmptyString<any>>().type.toBe<true>()
|
||||
|
||||
expect<IsEmptyString<'nonempty'>>().type.toBe<false>()
|
||||
expect<IsEmptyString<never>>().type.toBe<false>()
|
||||
Reference in New Issue
Block a user