-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from andnp/StrictUnion
Add StrictUnion
- Loading branch information
Showing
4 changed files
with
111 additions
and
1 deletion.
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 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,22 @@ | ||
import test from 'ava'; | ||
import { assert } from '../helpers/assert'; | ||
|
||
import { StrictUnion } from '../../src'; | ||
|
||
test('disallow union members with mixed properties', t => { | ||
type a = { a: number }; | ||
type b = { b: string }; | ||
|
||
type good1 = {a: 1}; | ||
type good2 = {b: "b"}; | ||
type bad = {a: 1, b: "foo"}; | ||
|
||
type isStrict<T> = T extends Array<StrictUnion<a | b>> ? 'Yes' : 'No'; | ||
|
||
type strictUnion = [good1, good2]; | ||
type nonStrictUnion = [good1, good2, bad]; | ||
|
||
assert<isStrict<strictUnion>, 'Yes'>(t); | ||
assert<isStrict<nonStrictUnion>, 'No'>(t); | ||
|
||
}); |
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,16 @@ | ||
import test from 'ava'; | ||
import { assert } from '../helpers/assert'; | ||
|
||
import { AllKeys, UnionKeys } from '../../src'; | ||
|
||
test('Can get all keys between objects in a union', t => { | ||
type a = { w: number, x: string }; | ||
type b = { x: number, z: boolean }; | ||
type c = { y: boolean, z: string }; | ||
|
||
type got = UnionKeys<a | b | c>; | ||
type expected = 'w' | 'x' | 'y' | 'z'; | ||
|
||
assert<got, expected>(t); | ||
assert<expected, got>(t); | ||
}); |