Skip to content

Commit 22a0ee5

Browse files
committed
Add test case from microsoft#26627
1 parent 3b9dad7 commit 22a0ee5

4 files changed

+145
-0
lines changed

tests/baselines/reference/identicalGenericConditionalsWithInferRelated.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,41 @@ function f<X>(arg: X) {
88
x = y; // is err, should be ok
99
y = x; // is err, should be ok
1010
}
11+
12+
// repro from https://github.com/microsoft/TypeScript/issues/26627
13+
export type Constructor<T> = new (...args: any[]) => T
14+
export type MappedResult<T> =
15+
T extends Boolean ? boolean :
16+
T extends Number ? number :
17+
T extends String ? string :
18+
T
19+
20+
21+
interface X {
22+
decode<C extends Constructor<any>>(ctor: C): MappedResult<C extends Constructor<infer T> ? T : never>
23+
}
24+
25+
class Y implements X {
26+
decode<C extends Constructor<any>>(ctor: C): MappedResult<C extends Constructor<infer T> ? T : never> {
27+
throw new Error()
28+
}
29+
}
1130

1231

1332
//// [identicalGenericConditionalsWithInferRelated.js]
33+
"use strict";
34+
exports.__esModule = true;
1435
function f(arg) {
1536
var x = null;
1637
var y = null;
1738
x = y; // is err, should be ok
1839
y = x; // is err, should be ok
1940
}
41+
var Y = /** @class */ (function () {
42+
function Y() {
43+
}
44+
Y.prototype.decode = function (ctor) {
45+
throw new Error();
46+
};
47+
return Y;
48+
}());

tests/baselines/reference/identicalGenericConditionalsWithInferRelated.symbols

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,67 @@ function f<X>(arg: X) {
3434
>x : Symbol(x, Decl(identicalGenericConditionalsWithInferRelated.ts, 4, 7))
3535
}
3636

37+
// repro from https://github.com/microsoft/TypeScript/issues/26627
38+
export type Constructor<T> = new (...args: any[]) => T
39+
>Constructor : Symbol(Constructor, Decl(identicalGenericConditionalsWithInferRelated.ts, 8, 1))
40+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 11, 24))
41+
>args : Symbol(args, Decl(identicalGenericConditionalsWithInferRelated.ts, 11, 34))
42+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 11, 24))
43+
44+
export type MappedResult<T> =
45+
>MappedResult : Symbol(MappedResult, Decl(identicalGenericConditionalsWithInferRelated.ts, 11, 54))
46+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 12, 25))
47+
48+
T extends Boolean ? boolean :
49+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 12, 25))
50+
>Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
51+
52+
T extends Number ? number :
53+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 12, 25))
54+
>Number : Symbol(Number, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
55+
56+
T extends String ? string :
57+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 12, 25))
58+
>String : Symbol(String, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
59+
60+
T
61+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 12, 25))
62+
63+
64+
interface X {
65+
>X : Symbol(X, Decl(identicalGenericConditionalsWithInferRelated.ts, 16, 5))
66+
67+
decode<C extends Constructor<any>>(ctor: C): MappedResult<C extends Constructor<infer T> ? T : never>
68+
>decode : Symbol(X.decode, Decl(identicalGenericConditionalsWithInferRelated.ts, 19, 13))
69+
>C : Symbol(C, Decl(identicalGenericConditionalsWithInferRelated.ts, 20, 11))
70+
>Constructor : Symbol(Constructor, Decl(identicalGenericConditionalsWithInferRelated.ts, 8, 1))
71+
>ctor : Symbol(ctor, Decl(identicalGenericConditionalsWithInferRelated.ts, 20, 39))
72+
>C : Symbol(C, Decl(identicalGenericConditionalsWithInferRelated.ts, 20, 11))
73+
>MappedResult : Symbol(MappedResult, Decl(identicalGenericConditionalsWithInferRelated.ts, 11, 54))
74+
>C : Symbol(C, Decl(identicalGenericConditionalsWithInferRelated.ts, 20, 11))
75+
>Constructor : Symbol(Constructor, Decl(identicalGenericConditionalsWithInferRelated.ts, 8, 1))
76+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 20, 89))
77+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 20, 89))
78+
}
79+
80+
class Y implements X {
81+
>Y : Symbol(Y, Decl(identicalGenericConditionalsWithInferRelated.ts, 21, 1))
82+
>X : Symbol(X, Decl(identicalGenericConditionalsWithInferRelated.ts, 16, 5))
83+
84+
decode<C extends Constructor<any>>(ctor: C): MappedResult<C extends Constructor<infer T> ? T : never> {
85+
>decode : Symbol(Y.decode, Decl(identicalGenericConditionalsWithInferRelated.ts, 23, 22))
86+
>C : Symbol(C, Decl(identicalGenericConditionalsWithInferRelated.ts, 24, 11))
87+
>Constructor : Symbol(Constructor, Decl(identicalGenericConditionalsWithInferRelated.ts, 8, 1))
88+
>ctor : Symbol(ctor, Decl(identicalGenericConditionalsWithInferRelated.ts, 24, 39))
89+
>C : Symbol(C, Decl(identicalGenericConditionalsWithInferRelated.ts, 24, 11))
90+
>MappedResult : Symbol(MappedResult, Decl(identicalGenericConditionalsWithInferRelated.ts, 11, 54))
91+
>C : Symbol(C, Decl(identicalGenericConditionalsWithInferRelated.ts, 24, 11))
92+
>Constructor : Symbol(Constructor, Decl(identicalGenericConditionalsWithInferRelated.ts, 8, 1))
93+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 24, 89))
94+
>T : Symbol(T, Decl(identicalGenericConditionalsWithInferRelated.ts, 24, 89))
95+
96+
throw new Error()
97+
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
98+
}
99+
}
100+

tests/baselines/reference/identicalGenericConditionalsWithInferRelated.types

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,36 @@ function f<X>(arg: X) {
3030
>x : X extends [infer A] ? A : never
3131
}
3232

33+
// repro from https://github.com/microsoft/TypeScript/issues/26627
34+
export type Constructor<T> = new (...args: any[]) => T
35+
>Constructor : Constructor<T>
36+
>args : any[]
37+
38+
export type MappedResult<T> =
39+
>MappedResult : MappedResult<T>
40+
41+
T extends Boolean ? boolean :
42+
T extends Number ? number :
43+
T extends String ? string :
44+
T
45+
46+
47+
interface X {
48+
decode<C extends Constructor<any>>(ctor: C): MappedResult<C extends Constructor<infer T> ? T : never>
49+
>decode : <C extends Constructor<any>>(ctor: C) => MappedResult<C extends Constructor<infer T> ? T : never>
50+
>ctor : C
51+
}
52+
53+
class Y implements X {
54+
>Y : Y
55+
56+
decode<C extends Constructor<any>>(ctor: C): MappedResult<C extends Constructor<infer T> ? T : never> {
57+
>decode : <C extends Constructor<any>>(ctor: C) => MappedResult<C extends Constructor<infer T> ? T : never>
58+
>ctor : C
59+
60+
throw new Error()
61+
>new Error() : Error
62+
>Error : ErrorConstructor
63+
}
64+
}
65+

tests/cases/compiler/identicalGenericConditionalsWithInferRelated.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,22 @@ function f<X>(arg: X) {
77
x = y; // is err, should be ok
88
y = x; // is err, should be ok
99
}
10+
11+
// repro from https://github.com/microsoft/TypeScript/issues/26627
12+
export type Constructor<T> = new (...args: any[]) => T
13+
export type MappedResult<T> =
14+
T extends Boolean ? boolean :
15+
T extends Number ? number :
16+
T extends String ? string :
17+
T
18+
19+
20+
interface X {
21+
decode<C extends Constructor<any>>(ctor: C): MappedResult<C extends Constructor<infer T> ? T : never>
22+
}
23+
24+
class Y implements X {
25+
decode<C extends Constructor<any>>(ctor: C): MappedResult<C extends Constructor<infer T> ? T : never> {
26+
throw new Error()
27+
}
28+
}

0 commit comments

Comments
 (0)