Skip to content

Commit

Permalink
feat(Conditionals): Add IfNot
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWrexes committed Jun 1, 2023
1 parent 3b8dd94 commit 8988ca7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tests/Conditionals.test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IsNever,
IfNever,
MutuallyExtend,
IfNot,
} from '../types'

type __TEST__ = {
Expand All @@ -20,6 +21,11 @@ type __TEST__ = {
ExpectTrue<If<true, true, false>>,
ExpectFalse<If<false, true, false>>,
]
// prettier-ignore
IfNot: [
ExpectTrue<IfNot<false, true, false>>,
ExpectFalse<IfNot<true, true, false>>
]
// If any edge case comes up when this type misbehaves,
// add it here before editing the type.
Extends: [
Expand Down
11 changes: 10 additions & 1 deletion types/Conditionals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { ExpectExtends, IsAny, NotAny as IsNotAny } from '@type-challenges/utils

export { IsAny, IsNotAny, ExpectExtends }

export type If<Test extends boolean, OnTrue, OnFalse = never> = Test extends true ? OnTrue : OnFalse
// prettier-ignore
export type If<Test extends boolean, OnTrue, OnFalse = never>
= Test extends true
? OnTrue
: OnFalse
// prettier-ignore
export type IfNot<Test extends boolean, OnFalse, OnTrue = never>
= Test extends false
? OnFalse
: OnTrue

// prettier-ignore
export type Extends<Type, ToExtend>
Expand Down

0 comments on commit 8988ca7

Please sign in to comment.