-
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
1 parent
e58c1c5
commit 9538b47
Showing
3 changed files
with
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@crbroughton/ts-test-utils": minor | ||
--- | ||
|
||
Add GetArrayUnion type |
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,18 @@ | ||
/* eslint-disable unused-imports/no-unused-vars */ | ||
import type { Equals, Expect, GetArrayUnion } from '..' | ||
|
||
// Passes the GetArrayUnion test when the resulting type matches the number array | ||
const testArray = [1, 2, 3] | ||
type Result = Expect<Equals<GetArrayUnion<typeof testArray>, number>> | ||
// ^? | ||
|
||
// Passes the GetArrayUnion test when the resulting type matches the array with const | ||
const testArrayConst = [1, 2, 'stringHere'] as const | ||
type ResultConst = Expect<Equals<GetArrayUnion<typeof testArrayConst>, 1 | 2 | 'stringHere'>> | ||
// ^? | ||
|
||
// Failed the GetArrayUnion test when the resulting type does equal the expectation | ||
const testArrayFail = [1, 2, 'stringHere'] as const | ||
// @ts-expect-error - GetParameters failing the equality checker | ||
type ResultFailure = Expect<Equals<GetParameters<typeof testArrayFail>, number | string>> | ||
// ^? |