-
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(types): Added StrictOmit, FN types
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { FN } from '../src'; | ||
import { describe, test, expectTypeOf } from 'vitest'; | ||
|
||
describe('FN', () => { | ||
test('any function type', () => { | ||
// biome-ignore lint/suspicious/noExplicitAny: testing | ||
const fn = (...args: any[]) => { | ||
return args?.[0]; | ||
}; | ||
|
||
type Expected = FN; | ||
|
||
type Actual = typeof fn; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
|
||
test('any any[] function type', () => { | ||
// biome-ignore lint/suspicious/noExplicitAny: testing | ||
const fn = (...args: any[]) => { | ||
return args; | ||
}; | ||
|
||
// biome-ignore lint/suspicious/noExplicitAny: testing | ||
type Expected = FN<any[]>; | ||
|
||
type Actual = typeof fn; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
|
||
test('string void function type', () => { | ||
const fn = (...args: string[]) => console.log(args); | ||
|
||
type Expected = FN<void, string>; | ||
|
||
type Actual = typeof fn; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
}); |
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,19 @@ | ||
import type { StrictOmit } from '../src'; | ||
import { describe, test, expectTypeOf } from 'vitest'; | ||
|
||
describe('Strict Omit', () => { | ||
test('type omit keys of object from object', () => { | ||
const obj = { | ||
Bob: 'bob', | ||
Bert: 'bert', | ||
}; | ||
|
||
type Expected = { | ||
Bob: string; | ||
}; | ||
|
||
type Actual = StrictOmit<typeof obj, 'Bert'>; | ||
|
||
expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
}); | ||
}); |