Skip to content

Commit 3a10dd2

Browse files
committed
add extra test case
1 parent ed80c21 commit 3a10dd2

4 files changed

Lines changed: 100 additions & 1 deletion

File tree

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27162,7 +27162,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2716227162

2716327163
function inferToConditionalType(source: Type, target: ConditionalType) {
2716427164
const info = target.root.isDistributive ? getInferenceInfoForType(getActualTypeVariable(target.checkType)) : undefined;
27165-
const saveIndividualPriority = info?.individualPriority
27165+
const saveIndividualPriority = info?.individualPriority;
2716627166
if (info) {
2716727167
info.individualPriority = (info.individualPriority || InferencePriority.None) | InferencePriority.DistributiveConditional;
2716827168
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [tests/cases/compiler/inferToDistributiveConditionalType1.ts] ////
2+
3+
=== inferToDistributiveConditionalType1.ts ===
4+
declare class Animal { eat(): void; }
5+
>Animal : Symbol(Animal, Decl(inferToDistributiveConditionalType1.ts, 0, 0))
6+
>eat : Symbol(Animal.eat, Decl(inferToDistributiveConditionalType1.ts, 0, 22))
7+
8+
declare class Cat extends Animal { meow(): void; }
9+
>Cat : Symbol(Cat, Decl(inferToDistributiveConditionalType1.ts, 0, 37))
10+
>Animal : Symbol(Animal, Decl(inferToDistributiveConditionalType1.ts, 0, 0))
11+
>meow : Symbol(Cat.meow, Decl(inferToDistributiveConditionalType1.ts, 1, 34))
12+
13+
declare class Dog extends Animal { bark(): void; }
14+
>Dog : Symbol(Dog, Decl(inferToDistributiveConditionalType1.ts, 1, 50))
15+
>Animal : Symbol(Animal, Decl(inferToDistributiveConditionalType1.ts, 0, 0))
16+
>bark : Symbol(Dog.bark, Decl(inferToDistributiveConditionalType1.ts, 2, 34))
17+
18+
declare function test1<T>(a: T extends unknown ? { prop: T } : never): T;
19+
>test1 : Symbol(test1, Decl(inferToDistributiveConditionalType1.ts, 2, 50))
20+
>T : Symbol(T, Decl(inferToDistributiveConditionalType1.ts, 4, 23))
21+
>a : Symbol(a, Decl(inferToDistributiveConditionalType1.ts, 4, 26))
22+
>T : Symbol(T, Decl(inferToDistributiveConditionalType1.ts, 4, 23))
23+
>prop : Symbol(prop, Decl(inferToDistributiveConditionalType1.ts, 4, 50))
24+
>T : Symbol(T, Decl(inferToDistributiveConditionalType1.ts, 4, 23))
25+
>T : Symbol(T, Decl(inferToDistributiveConditionalType1.ts, 4, 23))
26+
27+
declare const arg1: { prop: Dog } | { prop: Cat };
28+
>arg1 : Symbol(arg1, Decl(inferToDistributiveConditionalType1.ts, 5, 13))
29+
>prop : Symbol(prop, Decl(inferToDistributiveConditionalType1.ts, 5, 21))
30+
>Dog : Symbol(Dog, Decl(inferToDistributiveConditionalType1.ts, 1, 50))
31+
>prop : Symbol(prop, Decl(inferToDistributiveConditionalType1.ts, 5, 37))
32+
>Cat : Symbol(Cat, Decl(inferToDistributiveConditionalType1.ts, 0, 37))
33+
34+
const result1 = test1(arg1);
35+
>result1 : Symbol(result1, Decl(inferToDistributiveConditionalType1.ts, 6, 5))
36+
>test1 : Symbol(test1, Decl(inferToDistributiveConditionalType1.ts, 2, 50))
37+
>arg1 : Symbol(arg1, Decl(inferToDistributiveConditionalType1.ts, 5, 13))
38+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//// [tests/cases/compiler/inferToDistributiveConditionalType1.ts] ////
2+
3+
=== inferToDistributiveConditionalType1.ts ===
4+
declare class Animal { eat(): void; }
5+
>Animal : Animal
6+
> : ^^^^^^
7+
>eat : () => void
8+
> : ^^^^^^
9+
10+
declare class Cat extends Animal { meow(): void; }
11+
>Cat : Cat
12+
> : ^^^
13+
>Animal : Animal
14+
> : ^^^^^^
15+
>meow : () => void
16+
> : ^^^^^^
17+
18+
declare class Dog extends Animal { bark(): void; }
19+
>Dog : Dog
20+
> : ^^^
21+
>Animal : Animal
22+
> : ^^^^^^
23+
>bark : () => void
24+
> : ^^^^^^
25+
26+
declare function test1<T>(a: T extends unknown ? { prop: T } : never): T;
27+
>test1 : <T>(a: T extends unknown ? { prop: T; } : never) => T
28+
> : ^ ^^ ^^ ^^^^^
29+
>a : T extends unknown ? { prop: T; } : never
30+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
31+
>prop : T
32+
> : ^
33+
34+
declare const arg1: { prop: Dog } | { prop: Cat };
35+
>arg1 : { prop: Dog; } | { prop: Cat; }
36+
> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^
37+
>prop : Dog
38+
> : ^^^
39+
>prop : Cat
40+
> : ^^^
41+
42+
const result1 = test1(arg1);
43+
>result1 : Cat | Dog
44+
> : ^^^^^^^^^
45+
>test1(arg1) : Cat | Dog
46+
> : ^^^^^^^^^
47+
>test1 : <T>(a: T extends unknown ? { prop: T; } : never) => T
48+
> : ^ ^^ ^^ ^^^^^
49+
>arg1 : { prop: Dog; } | { prop: Cat; }
50+
> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^
51+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
declare class Animal { eat(): void; }
5+
declare class Cat extends Animal { meow(): void; }
6+
declare class Dog extends Animal { bark(): void; }
7+
8+
declare function test1<T>(a: T extends unknown ? { prop: T } : never): T;
9+
declare const arg1: { prop: Dog } | { prop: Cat };
10+
const result1 = test1(arg1);

0 commit comments

Comments
 (0)