Skip to content

Commit c930895

Browse files
authored
Undo 'any' inference propagation (microsoft#22736)
* Undo 'any' inference propagation Removing this only changes one test slightly, and fixes JQuery types, which rely on the old method of inference. * Add jquery regression test and update baselines * Restore any inference propagation to wildcard only
1 parent 6a86534 commit c930895

File tree

6 files changed

+146
-5
lines changed

6 files changed

+146
-5
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11594,7 +11594,7 @@ namespace ts {
1159411594
if (!couldContainTypeVariables(target)) {
1159511595
return;
1159611596
}
11597-
if (source.flags & TypeFlags.Any) {
11597+
if (source === wildcardType) {
1159811598
// We are inferring from an 'any' type. We want to infer this type for every type parameter
1159911599
// referenced in the target type, so we record it as the propagation type and infer from the
1160011600
// target to itself. Then, as we find candidates we substitute the propagation type.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [jqueryInference.ts]
2+
// #22362
3+
interface MyPromise<T, U> {
4+
then(cb: (t: T) => void): void;
5+
thenUnion(cb: (t: T | U) => void): this;
6+
}
7+
8+
interface DoNothingAlias<T, U> extends MyPromise<T, U> { }
9+
10+
declare function shouldBeIdentity<T, U>(p: DoNothingAlias<T, U>): MyPromise<T, U>;
11+
12+
declare const p1: MyPromise<boolean, any>;
13+
var p2 = shouldBeIdentity(p1);
14+
var p2: MyPromise<boolean, {}>;
15+
16+
17+
//// [jqueryInference.js]
18+
var p2 = shouldBeIdentity(p1);
19+
var p2;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
=== tests/cases/compiler/jqueryInference.ts ===
2+
// #22362
3+
interface MyPromise<T, U> {
4+
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
5+
>T : Symbol(T, Decl(jqueryInference.ts, 1, 20))
6+
>U : Symbol(U, Decl(jqueryInference.ts, 1, 22))
7+
8+
then(cb: (t: T) => void): void;
9+
>then : Symbol(MyPromise.then, Decl(jqueryInference.ts, 1, 27))
10+
>cb : Symbol(cb, Decl(jqueryInference.ts, 2, 9))
11+
>t : Symbol(t, Decl(jqueryInference.ts, 2, 14))
12+
>T : Symbol(T, Decl(jqueryInference.ts, 1, 20))
13+
14+
thenUnion(cb: (t: T | U) => void): this;
15+
>thenUnion : Symbol(MyPromise.thenUnion, Decl(jqueryInference.ts, 2, 35))
16+
>cb : Symbol(cb, Decl(jqueryInference.ts, 3, 14))
17+
>t : Symbol(t, Decl(jqueryInference.ts, 3, 19))
18+
>T : Symbol(T, Decl(jqueryInference.ts, 1, 20))
19+
>U : Symbol(U, Decl(jqueryInference.ts, 1, 22))
20+
}
21+
22+
interface DoNothingAlias<T, U> extends MyPromise<T, U> { }
23+
>DoNothingAlias : Symbol(DoNothingAlias, Decl(jqueryInference.ts, 4, 1))
24+
>T : Symbol(T, Decl(jqueryInference.ts, 6, 25))
25+
>U : Symbol(U, Decl(jqueryInference.ts, 6, 27))
26+
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
27+
>T : Symbol(T, Decl(jqueryInference.ts, 6, 25))
28+
>U : Symbol(U, Decl(jqueryInference.ts, 6, 27))
29+
30+
declare function shouldBeIdentity<T, U>(p: DoNothingAlias<T, U>): MyPromise<T, U>;
31+
>shouldBeIdentity : Symbol(shouldBeIdentity, Decl(jqueryInference.ts, 6, 58))
32+
>T : Symbol(T, Decl(jqueryInference.ts, 8, 34))
33+
>U : Symbol(U, Decl(jqueryInference.ts, 8, 36))
34+
>p : Symbol(p, Decl(jqueryInference.ts, 8, 40))
35+
>DoNothingAlias : Symbol(DoNothingAlias, Decl(jqueryInference.ts, 4, 1))
36+
>T : Symbol(T, Decl(jqueryInference.ts, 8, 34))
37+
>U : Symbol(U, Decl(jqueryInference.ts, 8, 36))
38+
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
39+
>T : Symbol(T, Decl(jqueryInference.ts, 8, 34))
40+
>U : Symbol(U, Decl(jqueryInference.ts, 8, 36))
41+
42+
declare const p1: MyPromise<boolean, any>;
43+
>p1 : Symbol(p1, Decl(jqueryInference.ts, 10, 13))
44+
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
45+
46+
var p2 = shouldBeIdentity(p1);
47+
>p2 : Symbol(p2, Decl(jqueryInference.ts, 11, 3), Decl(jqueryInference.ts, 12, 3))
48+
>shouldBeIdentity : Symbol(shouldBeIdentity, Decl(jqueryInference.ts, 6, 58))
49+
>p1 : Symbol(p1, Decl(jqueryInference.ts, 10, 13))
50+
51+
var p2: MyPromise<boolean, {}>;
52+
>p2 : Symbol(p2, Decl(jqueryInference.ts, 11, 3), Decl(jqueryInference.ts, 12, 3))
53+
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
54+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
=== tests/cases/compiler/jqueryInference.ts ===
2+
// #22362
3+
interface MyPromise<T, U> {
4+
>MyPromise : MyPromise<T, U>
5+
>T : T
6+
>U : U
7+
8+
then(cb: (t: T) => void): void;
9+
>then : (cb: (t: T) => void) => void
10+
>cb : (t: T) => void
11+
>t : T
12+
>T : T
13+
14+
thenUnion(cb: (t: T | U) => void): this;
15+
>thenUnion : (cb: (t: T | U) => void) => this
16+
>cb : (t: T | U) => void
17+
>t : T | U
18+
>T : T
19+
>U : U
20+
}
21+
22+
interface DoNothingAlias<T, U> extends MyPromise<T, U> { }
23+
>DoNothingAlias : DoNothingAlias<T, U>
24+
>T : T
25+
>U : U
26+
>MyPromise : MyPromise<T, U>
27+
>T : T
28+
>U : U
29+
30+
declare function shouldBeIdentity<T, U>(p: DoNothingAlias<T, U>): MyPromise<T, U>;
31+
>shouldBeIdentity : <T, U>(p: DoNothingAlias<T, U>) => MyPromise<T, U>
32+
>T : T
33+
>U : U
34+
>p : DoNothingAlias<T, U>
35+
>DoNothingAlias : DoNothingAlias<T, U>
36+
>T : T
37+
>U : U
38+
>MyPromise : MyPromise<T, U>
39+
>T : T
40+
>U : U
41+
42+
declare const p1: MyPromise<boolean, any>;
43+
>p1 : MyPromise<boolean, any>
44+
>MyPromise : MyPromise<T, U>
45+
46+
var p2 = shouldBeIdentity(p1);
47+
>p2 : MyPromise<boolean, {}>
48+
>shouldBeIdentity(p1) : MyPromise<boolean, {}>
49+
>shouldBeIdentity : <T, U>(p: DoNothingAlias<T, U>) => MyPromise<T, U>
50+
>p1 : MyPromise<boolean, any>
51+
52+
var p2: MyPromise<boolean, {}>;
53+
>p2 : MyPromise<boolean, {}>
54+
>MyPromise : MyPromise<T, U>
55+

tests/baselines/reference/mappedTypeRecursiveInference.types

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// #22362
2+
interface MyPromise<T, U> {
3+
then(cb: (t: T) => void): void;
4+
thenUnion(cb: (t: T | U) => void): this;
5+
}
6+
7+
interface DoNothingAlias<T, U> extends MyPromise<T, U> { }
8+
9+
declare function shouldBeIdentity<T, U>(p: DoNothingAlias<T, U>): MyPromise<T, U>;
10+
11+
declare const p1: MyPromise<boolean, any>;
12+
var p2 = shouldBeIdentity(p1);
13+
var p2: MyPromise<boolean, {}>;

0 commit comments

Comments
 (0)