Skip to content

Commit 0832fd3

Browse files
committed
Improve document comments of is
1 parent 74fd7fb commit 0832fd3

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

is.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1+
/**
2+
* A type decision function
3+
*/
14
export type Predicate<T> = (x: unknown) => x is T;
25

36
/**
4-
* Return true if the value is string
7+
* Return `true` if the type of `x` is `string`.
58
*/
69
export function isString(x: unknown): x is string {
710
return typeof x === "string";
811
}
912

1013
/**
11-
* Return true if the value is number
14+
* Return `true` if the type of `x` is `number`.
1215
*/
1316
export function isNumber(x: unknown): x is number {
1417
return typeof x === "number";
1518
}
1619

1720
/**
18-
* Return true if the value is boolean
21+
* Return `true` if the type of `x` is `boolean`.
1922
*/
2023
export function isBoolean(x: unknown): x is boolean {
2124
return typeof x === "boolean";
2225
}
2326

2427
/**
25-
* Return true if the value is array
28+
* Return `true` if the type of `x` is `array`.
29+
*
30+
* Use `pred` to predicate the type of items.
2631
*/
2732
export function isArray<T extends unknown>(
2833
x: unknown,
@@ -32,7 +37,9 @@ export function isArray<T extends unknown>(
3237
}
3338

3439
/**
35-
* Return true if the value is object
40+
* Return `true` if the type of `x` is `object`.
41+
*
42+
* Use `pred` to predicate the type of values.
3643
*/
3744
export function isObject<T extends unknown>(
3845
x: unknown,
@@ -47,35 +54,35 @@ export function isObject<T extends unknown>(
4754
}
4855

4956
/**
50-
* Return true if the value is function
57+
* Return `true` if the type of `x` is `function`.
5158
*/
5259
export function isFunction(x: unknown): x is (...args: unknown[]) => unknown {
5360
return Object.prototype.toString.call(x) === "[object Function]";
5461
}
5562

5663
/**
57-
* Return true if the value is null
64+
* Return `true` if the type of `x` is `null`.
5865
*/
5966
export function isNull(x: unknown): x is null {
6067
return x === null;
6168
}
6269

6370
/**
64-
* Return true if the value is undefined
71+
* Return `true` if the type of `x` is `undefined`.
6572
*/
6673
export function isUndefined(x: unknown): x is undefined {
6774
return typeof x === "undefined";
6875
}
6976

7077
/**
71-
* Return true if the value is null or undefined
78+
* Return `true` if the type of `x` is `null` or `undefined`.
7279
*/
7380
export function isNullish(x: unknown): x is null | undefined {
7481
return x == null;
7582
}
7683

7784
/**
78-
* Return true if a type of value is like a type of reference.
85+
* Return `true` if the type of `x` follows the type of `ref`.
7986
*/
8087
export function isLike<R, T extends unknown>(
8188
ref: R,

0 commit comments

Comments
 (0)