Merge pull request #13623 from Microsoft/fixIntersectionApparentType

Fix intersection apparent type
This commit is contained in:
Anders Hejlsberg 2017-01-22 11:55:41 -10:00 committed by GitHub
commit 3cf326a8c4
5 changed files with 107 additions and 1 deletions

View File

@ -4871,7 +4871,7 @@ namespace ts {
*/
function getApparentType(type: Type): Type {
const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(<TypeVariable>type) || emptyObjectType : type;
return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>type) :
return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>t) :
t.flags & TypeFlags.StringLike ? globalStringType :
t.flags & TypeFlags.NumberLike ? globalNumberType :
t.flags & TypeFlags.BooleanLike ? globalBooleanType :

View File

@ -504,6 +504,18 @@ function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
// Repro from #13514
declare function head<T extends Array<any>>(list: T): T[0];
// Repro from #13604
class A<T> {
props: T & { foo: string };
}
class B extends A<{ x: number}> {
f(p: this["props"]) {
p.x;
}
}
//// [keyofAndIndexedAccess.js]
@ -834,6 +846,22 @@ function updateIds2(obj, key, stringMap) {
var x = obj[key];
stringMap[x]; // Should be OK.
}
// Repro from #13604
var A = (function () {
function A() {
}
return A;
}());
var B = (function (_super) {
__extends(B, _super);
function B() {
return _super !== null && _super.apply(this, arguments) || this;
}
B.prototype.f = function (p) {
p.x;
};
return B;
}(A));
//// [keyofAndIndexedAccess.d.ts]
@ -1066,3 +1094,13 @@ declare function updateIds2<T extends {
[oldId: string]: string;
}): void;
declare function head<T extends Array<any>>(list: T): T[0];
declare class A<T> {
props: T & {
foo: string;
};
}
declare class B extends A<{
x: number;
}> {
f(p: this["props"]): void;
}

View File

@ -1816,3 +1816,31 @@ declare function head<T extends Array<any>>(list: T): T[0];
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 504, 22))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 504, 22))
// Repro from #13604
class A<T> {
>A : Symbol(A, Decl(keyofAndIndexedAccess.ts, 504, 59))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 508, 8))
props: T & { foo: string };
>props : Symbol(A.props, Decl(keyofAndIndexedAccess.ts, 508, 12))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 508, 8))
>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 509, 13))
}
class B extends A<{ x: number}> {
>B : Symbol(B, Decl(keyofAndIndexedAccess.ts, 510, 1))
>A : Symbol(A, Decl(keyofAndIndexedAccess.ts, 504, 59))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 512, 19))
f(p: this["props"]) {
>f : Symbol(B.f, Decl(keyofAndIndexedAccess.ts, 512, 33))
>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 513, 3))
p.x;
>p.x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 512, 19))
>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 513, 3))
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 512, 19))
}
}

View File

@ -2138,3 +2138,31 @@ declare function head<T extends Array<any>>(list: T): T[0];
>T : T
>T : T
// Repro from #13604
class A<T> {
>A : A<T>
>T : T
props: T & { foo: string };
>props : T & { foo: string; }
>T : T
>foo : string
}
class B extends A<{ x: number}> {
>B : B
>A : A<{ x: number; }>
>x : number
f(p: this["props"]) {
>f : (p: this["props"]) => void
>p : this["props"]
p.x;
>p.x : number
>p : this["props"]
>x : number
}
}

View File

@ -505,3 +505,15 @@ function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
// Repro from #13514
declare function head<T extends Array<any>>(list: T): T[0];
// Repro from #13604
class A<T> {
props: T & { foo: string };
}
class B extends A<{ x: number}> {
f(p: this["props"]) {
p.x;
}
}