feat(typescript-types): Add If<Test,TrueBranch,FalseBranch>

This commit is contained in:
T. R. Bernstein
2025-07-13 03:06:29 +02:00
parent afe7bee342
commit 319ccac8a7
3 changed files with 31 additions and 4 deletions

View 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