Undo 'any' inference propagation (#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
This commit is contained in:
Nathan Shively-Sanders
2018-03-21 11:13:39 -07:00
committed by GitHub
parent 6a86534d81
commit c930895d80
6 changed files with 146 additions and 5 deletions

View File

@@ -11594,7 +11594,7 @@ namespace ts {
if (!couldContainTypeVariables(target)) {
return;
}
if (source.flags & TypeFlags.Any) {
if (source === wildcardType) {
// We are inferring from an 'any' type. We want to infer this type for every type parameter
// referenced in the target type, so we record it as the propagation type and infer from the
// target to itself. Then, as we find candidates we substitute the propagation type.

View File

@@ -0,0 +1,19 @@
//// [jqueryInference.ts]
// #22362
interface MyPromise<T, U> {
then(cb: (t: T) => void): void;
thenUnion(cb: (t: T | U) => void): this;
}
interface DoNothingAlias<T, U> extends MyPromise<T, U> { }
declare function shouldBeIdentity<T, U>(p: DoNothingAlias<T, U>): MyPromise<T, U>;
declare const p1: MyPromise<boolean, any>;
var p2 = shouldBeIdentity(p1);
var p2: MyPromise<boolean, {}>;
//// [jqueryInference.js]
var p2 = shouldBeIdentity(p1);
var p2;

View File

@@ -0,0 +1,54 @@
=== tests/cases/compiler/jqueryInference.ts ===
// #22362
interface MyPromise<T, U> {
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
>T : Symbol(T, Decl(jqueryInference.ts, 1, 20))
>U : Symbol(U, Decl(jqueryInference.ts, 1, 22))
then(cb: (t: T) => void): void;
>then : Symbol(MyPromise.then, Decl(jqueryInference.ts, 1, 27))
>cb : Symbol(cb, Decl(jqueryInference.ts, 2, 9))
>t : Symbol(t, Decl(jqueryInference.ts, 2, 14))
>T : Symbol(T, Decl(jqueryInference.ts, 1, 20))
thenUnion(cb: (t: T | U) => void): this;
>thenUnion : Symbol(MyPromise.thenUnion, Decl(jqueryInference.ts, 2, 35))
>cb : Symbol(cb, Decl(jqueryInference.ts, 3, 14))
>t : Symbol(t, Decl(jqueryInference.ts, 3, 19))
>T : Symbol(T, Decl(jqueryInference.ts, 1, 20))
>U : Symbol(U, Decl(jqueryInference.ts, 1, 22))
}
interface DoNothingAlias<T, U> extends MyPromise<T, U> { }
>DoNothingAlias : Symbol(DoNothingAlias, Decl(jqueryInference.ts, 4, 1))
>T : Symbol(T, Decl(jqueryInference.ts, 6, 25))
>U : Symbol(U, Decl(jqueryInference.ts, 6, 27))
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
>T : Symbol(T, Decl(jqueryInference.ts, 6, 25))
>U : Symbol(U, Decl(jqueryInference.ts, 6, 27))
declare function shouldBeIdentity<T, U>(p: DoNothingAlias<T, U>): MyPromise<T, U>;
>shouldBeIdentity : Symbol(shouldBeIdentity, Decl(jqueryInference.ts, 6, 58))
>T : Symbol(T, Decl(jqueryInference.ts, 8, 34))
>U : Symbol(U, Decl(jqueryInference.ts, 8, 36))
>p : Symbol(p, Decl(jqueryInference.ts, 8, 40))
>DoNothingAlias : Symbol(DoNothingAlias, Decl(jqueryInference.ts, 4, 1))
>T : Symbol(T, Decl(jqueryInference.ts, 8, 34))
>U : Symbol(U, Decl(jqueryInference.ts, 8, 36))
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
>T : Symbol(T, Decl(jqueryInference.ts, 8, 34))
>U : Symbol(U, Decl(jqueryInference.ts, 8, 36))
declare const p1: MyPromise<boolean, any>;
>p1 : Symbol(p1, Decl(jqueryInference.ts, 10, 13))
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))
var p2 = shouldBeIdentity(p1);
>p2 : Symbol(p2, Decl(jqueryInference.ts, 11, 3), Decl(jqueryInference.ts, 12, 3))
>shouldBeIdentity : Symbol(shouldBeIdentity, Decl(jqueryInference.ts, 6, 58))
>p1 : Symbol(p1, Decl(jqueryInference.ts, 10, 13))
var p2: MyPromise<boolean, {}>;
>p2 : Symbol(p2, Decl(jqueryInference.ts, 11, 3), Decl(jqueryInference.ts, 12, 3))
>MyPromise : Symbol(MyPromise, Decl(jqueryInference.ts, 0, 0))

View File

@@ -0,0 +1,55 @@
=== tests/cases/compiler/jqueryInference.ts ===
// #22362
interface MyPromise<T, U> {
>MyPromise : MyPromise<T, U>
>T : T
>U : U
then(cb: (t: T) => void): void;
>then : (cb: (t: T) => void) => void
>cb : (t: T) => void
>t : T
>T : T
thenUnion(cb: (t: T | U) => void): this;
>thenUnion : (cb: (t: T | U) => void) => this
>cb : (t: T | U) => void
>t : T | U
>T : T
>U : U
}
interface DoNothingAlias<T, U> extends MyPromise<T, U> { }
>DoNothingAlias : DoNothingAlias<T, U>
>T : T
>U : U
>MyPromise : MyPromise<T, U>
>T : T
>U : U
declare function shouldBeIdentity<T, U>(p: DoNothingAlias<T, U>): MyPromise<T, U>;
>shouldBeIdentity : <T, U>(p: DoNothingAlias<T, U>) => MyPromise<T, U>
>T : T
>U : U
>p : DoNothingAlias<T, U>
>DoNothingAlias : DoNothingAlias<T, U>
>T : T
>U : U
>MyPromise : MyPromise<T, U>
>T : T
>U : U
declare const p1: MyPromise<boolean, any>;
>p1 : MyPromise<boolean, any>
>MyPromise : MyPromise<T, U>
var p2 = shouldBeIdentity(p1);
>p2 : MyPromise<boolean, {}>
>shouldBeIdentity(p1) : MyPromise<boolean, {}>
>shouldBeIdentity : <T, U>(p: DoNothingAlias<T, U>) => MyPromise<T, U>
>p1 : MyPromise<boolean, any>
var p2: MyPromise<boolean, {}>;
>p2 : MyPromise<boolean, {}>
>MyPromise : MyPromise<T, U>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,13 @@
// #22362
interface MyPromise<T, U> {
then(cb: (t: T) => void): void;
thenUnion(cb: (t: T | U) => void): this;
}
interface DoNothingAlias<T, U> extends MyPromise<T, U> { }
declare function shouldBeIdentity<T, U>(p: DoNothingAlias<T, U>): MyPromise<T, U>;
declare const p1: MyPromise<boolean, any>;
var p2 = shouldBeIdentity(p1);
var p2: MyPromise<boolean, {}>;