File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 1+ // Function.
2+ import { isDefined } from '../../is/lib/is-defined.func' ;
3+ // Type.
4+ import { Defined } from '../../type/defined.type' ;
5+ import { GuardDefined } from '../type/guard-defined.type' ;
6+ import { ResultCallback } from '../../type/result-callback.type' ;
7+ /**
8+ * Checks if a generic type `value` is NOT an `undefined` type and is NOT equal to `undefined`.
9+ * @param value A generic type `value` to check.
10+ * @param callback An optional `ResultCallback` function to handle result before returns.
11+ * @returns A `boolean` indicating whether or not the `value` is defined, if `undefined` then returns `never`.
12+ */
13+ export const guardDefined : GuardDefined = < Type > ( value : Type , callback ?: ResultCallback ) : value is Defined < Type > =>
14+ isDefined ( value , callback ) ;
Original file line number Diff line number Diff line change 1+ import { Defined } from '../../type/defined.type' ;
2+ import { ResultCallback } from '../../type/result-callback.type' ;
3+ export type GuardDefined = < Type > ( value : Type , callback ?: ResultCallback ) => value is Defined < Type > ;
Original file line number Diff line number Diff line change 1+ export type Defined < T > = T extends undefined ? never : T ;
You can’t perform that action at this time.
0 commit comments