File tree Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,7 @@ export type {SharedUnionFields} from './source/shared-union-fields.d.ts';
145
145
export type { SharedUnionFieldsDeep } from './source/shared-union-fields-deep.d.ts' ;
146
146
export type { IsNull } from './source/is-null.d.ts' ;
147
147
export type { IfNull } from './source/if-null.d.ts' ;
148
+ export type { IsUndefined } from './source/is-undefined.d.ts' ;
148
149
export type { And } from './source/and.d.ts' ;
149
150
export type { Or } from './source/or.d.ts' ;
150
151
export type { AllExtend } from './source/all-extend.d.ts' ;
Original file line number Diff line number Diff line change @@ -199,6 +199,7 @@ Click the type names for complete docs.
199
199
- [ ` IsUnknown ` ] ( source/is-unknown.d.ts ) - Returns a boolean for whether the given type is ` unknown ` .
200
200
- [ ` IsEmptyObject ` ] ( source/empty-object.d.ts ) - Returns a boolean for whether the type is strictly equal to an empty plain object, the ` {} ` value.
201
201
- [ ` IsNull ` ] ( source/is-null.d.ts ) - Returns a boolean for whether the given type is ` null ` .
202
+ - [ ` IsUndefined ` ] ( source/is-undefined.d.ts ) - Returns a boolean for whether the given type is ` undefined ` .
202
203
- [ ` IsTuple ` ] ( source/is-tuple.d.ts ) - Returns a boolean for whether the given array is a tuple.
203
204
- [ ` IsUnion ` ] ( source/is-union.d.ts ) - Returns a boolean for whether the given type is a union.
204
205
- [ ` IsLowercase ` ] ( source/is-lowercase.d.ts ) - Returns a boolean for whether the given string literal is lowercase.
Original file line number Diff line number Diff line change
1
+ /**
2
+ Returns a boolean for whether the given type is `undefined`.
3
+
4
+ @example
5
+ ```
6
+ import type {IsUndefined} from 'type-fest';
7
+
8
+ type UndefinedFallback<T, Fallback> = IsUndefined<T> extends true ? Fallback : T;
9
+
10
+ type Example1 = UndefinedFallback<undefined, string>;
11
+ //=> string
12
+
13
+ type Example2 = UndefinedFallback<number, string>;
14
+ //=> number
15
+ ```
16
+
17
+ @category Type Guard
18
+ @category Utilities
19
+ */
20
+ export type IsUndefined < T > = [ T ] extends [ undefined ] ? true : false ;
Original file line number Diff line number Diff line change
1
+ import { expectType } from 'tsd' ;
2
+ import type { IsUndefined } from '../source/is-undefined.d.ts' ;
3
+
4
+ expectType < IsUndefined < undefined > > ( true ) ;
5
+ expectType < IsUndefined < any > > ( true ) ;
6
+ expectType < IsUndefined < never > > ( true ) ;
7
+ expectType < IsUndefined < null > > ( false ) ; // Depends on `strictNullChecks`
8
+ expectType < IsUndefined < unknown > > ( false ) ;
9
+ expectType < IsUndefined < void > > ( false ) ;
10
+ expectType < IsUndefined < { } > > ( false ) ;
You can’t perform that action at this time.
0 commit comments