Created
November 30, 2025 00:46
-
-
Save anztrax/b0947779a6888bdffd57fc7e015b2d05 to your computer and use it in GitHub Desktop.
simple implementation of If in Typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* _____________ Your Code Here _____________ */ | |
| type If<C extends boolean, T, F> = C extends true ? T: F | |
| /* _____________ Test Cases _____________ */ | |
| import type { Equal, Expect } from '@type-challenges/utils' | |
| type cases = [ | |
| Expect<Equal<If<true, 'a', 'b'>, 'a'>>, | |
| Expect<Equal<If<false, 'a', 2>, 2>>, | |
| Expect<Equal<If<boolean, 'a', 2>, 'a' | 2>>, | |
| ] | |
| // @ts-expect-error | |
| type error = If<null, 'a', 'b'> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment