Skip to content

Commit 8b984c9

Browse files
test: add test cases
1 parent 3b54932 commit 8b984c9

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

test-d/exclude-exactly.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ expectType<2>({} as ExcludeExactly<0 | 1 | 2, 0 | 1>);
3737
expectType<never>({} as ExcludeExactly<0 | 1 | 2, 0 | 1 | 2>);
3838
expectType<{readonly a?: 0}>({} as ExcludeExactly<{a: 0} | {readonly a: 0} | {a?: 0} | {readonly a?: 0}, {a: 0} | {readonly a: 0} | {a?: 0}>);
3939
expectType<never>({} as ExcludeExactly<{a: 0} | {readonly a: 0} | {a?: 0} | {readonly a?: 0}, {a: 0} | {readonly a: 0} | {a?: 0} | {readonly a?: 0}>);
40+
41+
// Identical Union
42+
expectType<never>({} as ExcludeExactly<{a: 0} | {a: 0}, {a: 0}>); // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
43+
44+
// Identical Intersection
45+
expectType<never>({} as ExcludeExactly<{a: 0} & {a: 0}, {a: 0}>); // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents

test-d/union-to-tuple.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,37 @@ type Options2 = UnionToTuple<boolean | 1>;
1313
expectType<Options2[number]>({} as (1 | false | true));
1414

1515
// Different modifiers cases.
16-
type DifferentModifiers = {a: 0} | {readonly a: 0} | {a?: 0} | {readonly a?: 0};
16+
type DifferentModifiers = {a: 0} | {readonly a: 0};
1717
expectType<UnionToTuple<DifferentModifiers>[number]>({} as DifferentModifiers);
18+
expectType<UnionToTuple<DifferentModifiers>['length']>(2);
19+
20+
type ReversedDifferentModifiers = {readonly a: 0} | {a: 0};
21+
expectType<UnionToTuple<ReversedDifferentModifiers>[number]>({} as ReversedDifferentModifiers);
22+
expectType<UnionToTuple<ReversedDifferentModifiers>['length']>(2);
1823

1924
// Super type cases.
2025
type UnionSuperType0 = {a: string; b: string} | {a: string};
2126
expectType<UnionSuperType0>({} as UnionToTuple<UnionSuperType0>[number]);
27+
expectType<UnionToTuple<UnionSuperType0>['length']>(2);
28+
29+
type ReversedUnionSuperType0 = {a: string} | {a: string; b: string};
30+
expectType<ReversedUnionSuperType0>({} as UnionToTuple<ReversedUnionSuperType0>[number]);
31+
expectType<UnionToTuple<ReversedUnionSuperType0>['length']>(2);
2232

23-
type UnionSuperType1 = {a: 1} | {b: 1} | {[x: string]: number};
33+
type UnionSuperType1 = {a: 1} | {[x: string]: number};
2434
expectType<UnionSuperType1>({} as UnionToTuple<UnionSuperType1>[number]);
35+
expectType<UnionToTuple<UnionSuperType1>['length']>(2);
36+
37+
type ReversedUnionSuperType1 = {[x: string]: number} | {a: 1};
38+
expectType<ReversedUnionSuperType1>({} as UnionToTuple<ReversedUnionSuperType1>[number]);
39+
expectType<UnionToTuple<ReversedUnionSuperType1>['length']>(2);
40+
41+
// Identical union cases.
42+
type UnionIdentical = {a: string} | {a: string}; // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
43+
expectType<UnionToTuple<UnionIdentical>['length']>(1);
44+
45+
type UnionIdenticalIntersection = {a: string} & {a: string} | {a: string}; // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
46+
expectType<UnionToTuple<UnionIdenticalIntersection>['length']>(1);
47+
48+
type ReversedUnionIdenticalIntersection = {a: string} | {a: string} & {a: string}; // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
49+
expectType<UnionToTuple<ReversedUnionIdenticalIntersection>['length']>(1);

0 commit comments

Comments
 (0)