Skip to content

Commit 9154c07

Browse files
refactor(isDefined): change value parameter type from any to Type cause it's possible to use statement value is Defined<Type>, update jsdoc
1 parent 51d1309 commit 9154c07

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/is/lib/is-defined.func.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
import { resultCallback } from '../../lib/result-callback.func';
33
import { typeOf } from '../../lib/type-of.func';
44
// Type.
5+
import { Defined } from '../../type/defined.type';
56
import { IsDefined } from '../type/is-defined.type';
67
import { ResultCallback } from '../../type/result-callback.type';
78
/**
8-
* Checks if an unknown `value` is NOT an `undefined` type and is NOT equal to `undefined`.
9-
* @param value An `unknown` `value` to check.
10-
* @param callback `ResultCallback` function to handle result before returns.
9+
* Checks if a generic type `value` is not an `undefined` type and is not equal to `undefined`.
10+
* @param value A generic type `value` to check.
11+
* @param callback A `ResultCallback` function to handle result before returns.
1112
* @returns A `boolean` indicating whether or not the `value` is defined, not `undefined`.
1213
*/
13-
export const isDefined: IsDefined = (value: unknown, callback: ResultCallback = resultCallback): boolean =>
14+
export const isDefined: IsDefined = <Type>(value: Type, callback: ResultCallback = resultCallback): value is Defined<Type> =>
1415
callback(typeOf(value) !== 'undefined' && typeof value !== 'undefined' && value !== undefined, value);

src/is/type/is-defined.type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
import { Defined } from '../../type/defined.type';
12
import { ResultCallback } from '../../type/result-callback.type';
2-
export type IsDefined = (value: unknown, callback?: ResultCallback) => boolean;
3+
export type IsDefined = <Type>(value: Type, callback?: ResultCallback) => value is Defined<Type>;

0 commit comments

Comments
 (0)