-
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.
- Loading branch information
Showing
5 changed files
with
50 additions
and
36 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
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 was deleted.
Oops, something went wrong.
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,34 @@ | ||
import { Nullable } from 'src'; | ||
import { describe, assertType, expect, expectTypeOf, test, it } from 'vitest'; | ||
|
||
test.fails('fail test', () => { | ||
type _T = { foo: boolean }; | ||
// @ts-expect-error, it cannot be a _T, it should error out | ||
expect(assertType<_T>(null)).rejects.toBe(true); | ||
}); | ||
|
||
test('concrete types', () => { | ||
expectTypeOf(null).toMatchTypeOf<Nullable>(); | ||
expectTypeOf(undefined).toMatchTypeOf<Nullable>(); | ||
}); | ||
|
||
describe('_', () => { | ||
it('should accept null', () => { | ||
const value: Nullable = null; | ||
expect(value).toBeNull(); | ||
}); | ||
it('should accept undefined', () => { | ||
const value: Nullable = undefined; | ||
expect(value).toBeUndefined(); | ||
}); | ||
|
||
it('should handle type unions with Nullable', () => { | ||
type _Union = string | Nullable; | ||
const value1: _Union = 'foo'; | ||
expect(value1).toBe('foo'); | ||
const value2: _Union = null; | ||
expect(value2).toBeNull(); | ||
const value3: _Union = undefined; | ||
expect(value3).toBeUndefined(); | ||
}); | ||
}); |
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