feat(typescript-types): Add If<Test,TrueBranch,FalseBranch>
This commit is contained in:
13
packages/typescript-types/src/if.ts
Normal file
13
packages/typescript-types/src/if.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { IsAny } from './is-any.js'
|
||||
import type { IsNever } from './is-never.js'
|
||||
|
||||
// Note: Returns a union of TrueBranch and FalseBranch if Test is any or boolean
|
||||
// Note: Returns FalseBranch if Test is never
|
||||
export type If<Test, TrueBranch, FalseBranch> =
|
||||
IsAny<Test> extends true
|
||||
? FalseBranch
|
||||
: IsNever<Test> extends true
|
||||
? FalseBranch
|
||||
: Test extends true
|
||||
? TrueBranch
|
||||
: FalseBranch
|
||||
Reference in New Issue
Block a user