-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Add IsNonNullish type - Check if a type is neither undefined …
…or null
- Loading branch information
1 parent
b1c6950
commit 3e11f02
Showing
5 changed files
with
40 additions
and
4 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,5 @@ | ||
--- | ||
"@crbroughton/ts-test-utils": minor | ||
--- | ||
|
||
Add IsNonNullish type - Check if a type is neither undefined or null |
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
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,25 @@ | ||
/* eslint-disable unused-imports/no-unused-vars */ | ||
import { describe, it } from 'bun:test' | ||
import type { Expect, IsNonNullish } from '../index' | ||
|
||
describe('IsNonNullish tests', () => { | ||
it('Passes the IsNonNullish test when the type is not nullish', () => { | ||
type ResultNull = Expect<IsNonNullish<{ id: number }>> | ||
// ^? | ||
type ResultUndefined = Expect<IsNonNullish<{ id: number }>> | ||
// ^? | ||
type ResultBoth = Expect<IsNonNullish<{ id: number }>> | ||
// ^? | ||
}) | ||
it('Failed the IsNonNullish test when the type is nullish', () => { | ||
// @ts-expect-error - Fails the exclusion | ||
type ResultNull = Expect<IsNonNullish<{ id: number } | null>> | ||
// ^? | ||
// @ts-expect-error - Fails the exclusion | ||
type ResultUndefined = Expect<IsNonNullish<{ id: number } | undefined>> | ||
// ^? | ||
// @ts-expect-error - Fails the exclusion | ||
type ResultBoth = Expect<IsNonNullish<{ id: number } | null | 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