Skip to content

Commit f21a86f

Browse files
committed
chore: update isNull and isUndefined
1 parent 5adc2f5 commit f21a86f

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

docs/reference/predicate/isNull.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This function can also serve as a type predicate in TypeScript, narrowing the ty
1010
## Signature
1111

1212
```typescript
13-
function isNull(x: unknown): x is null;
13+
function isNull(val: any): val is null
1414
```
1515

1616
### Parameters

docs/reference/predicate/isUndefined.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ This function can also serve as a type predicate in TypeScript, narrowing the ty
1010
## Signature
1111

1212
```typescript
13-
function isUndefined(x: unknown): x is undefined;
13+
function isUndefined(val: any): val is undefined
1414
```
1515

1616
### Parameters
1717

18-
- `x` (`unknown`): The value to test if it is `undefined`.
18+
- `x` (`any`): The value to test if it is `undefined`.
1919

2020
### Returns
2121

src/predicate/isNull.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { toString } from './_internal/toString';
2+
13
/**
24
* Checks if the given value is null.
35
*
@@ -18,6 +20,7 @@
1820
* console.log(isNull(value2)); // false
1921
* console.log(isNull(value3)); // false
2022
*/
21-
export function isNull(x: unknown): x is null {
22-
return x === null;
23+
24+
export function isNull(val: any): val is null {
25+
return toString(val) === '[object Null]';
2326
}

src/predicate/isUndefined.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { toString } from './_internal/toString';
2+
13
/**
24
* Checks if the given value is undefined.
35
*
@@ -18,6 +20,7 @@
1820
* console.log(isUndefined(value2)); // false
1921
* console.log(isUndefined(value3)); // false
2022
*/
21-
export function isUndefined(x: unknown): x is undefined {
22-
return x === undefined;
23+
24+
export function isUndefined(val: any): val is undefined {
25+
return toString(val) === '[object Undefined]';
2326
}

0 commit comments

Comments
 (0)