File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @crbroughton/ts-test-utils " : minor
3
+ ---
4
+
5
+ Add IsNullish type - Check if a type is either undefined or null
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ A collection of helper TypeScript types to test other TypeScript types. This col
16
16
- IsNonNullable - Check if a type is not nullable
17
17
- IsUndefined - Check if a type is undefined
18
18
- IsNonUndefined - Check if a type is not undefined
19
+ - IsNullish - Check if a type is either undefined or null
19
20
20
21
## Installation
21
22
Original file line number Diff line number Diff line change @@ -30,3 +30,9 @@ export type IsNonNullable<T> = IsNullable<T> extends true ? false : true
30
30
export type IsUndefined < T > = undefined extends T ? true : false
31
31
32
32
export type IsNonUndefined < T > = IsUndefined < T > extends true ? false : true
33
+
34
+ export type IsNullish < T > =
35
+ IsNullable < T > extends true ?
36
+ true
37
+ : IsUndefined < T > extends true ?
38
+ true : false
Original file line number Diff line number Diff line change
1
+ /* eslint-disable unused-imports/no-unused-vars */
2
+ import { describe , it } from 'bun:test'
3
+ import type { Expect , IsNullish } from '../index'
4
+
5
+ describe ( 'IsNullable tests' , ( ) => {
6
+ it ( 'Passes the IsNullable test when the type is nullable' , ( ) => {
7
+ type ResultNull = Expect < IsNullish < { id : number } | null > >
8
+ // ^?
9
+ type ResultUndefined = Expect < IsNullish < { id : number } | undefined > >
10
+ // ^?
11
+ type ResultBoth = Expect < IsNullish < { id : number } | null | undefined > >
12
+ // ^?
13
+ } )
14
+ it ( 'Failed the IsNullable test when the type is not nullable' , ( ) => {
15
+ // @ts -expect-error - Fails the exclusion
16
+ type Result = Expect < IsNullish < { id : string } > >
17
+ // ^?
18
+ } )
19
+ } )
You can’t perform that action at this time.
0 commit comments