-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(isNil): Accept generic type for inversion type extraction (#90)
- Loading branch information
1 parent
4d4f2ea
commit dbacd7a
Showing
3 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { expectType } from 'tsd'; | ||
import { filter, isNil } from '../es'; | ||
|
||
expectType<boolean>(isNil(1)); | ||
expectType<boolean>(isNil('a')); | ||
expectType<boolean>(isNil(true)); | ||
|
||
expectType<boolean>(isNil(null)); | ||
expectType<boolean>(isNil(undefined)); | ||
|
||
const maybeNumber = (): number | null => { | ||
if (Math.random() > 0.5) { | ||
return null; | ||
} | ||
return 123; | ||
}; | ||
|
||
expectType<number | null>(maybeNumber()); | ||
|
||
const r = maybeNumber(); | ||
|
||
if (isNil(r)) { | ||
expectType<null>(r); | ||
} | ||
|
||
expectType<undefined[]>(filter(isNil, [] as (string | undefined)[])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export function isNil(value: any): value is null | undefined; | ||
export function isNil<T>(value: T): value is ((null | undefined) & T); |