Skip to content

Fix intersection apparent type #13623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand Down
38 changes: 38 additions & 0 deletions tests/baselines/reference/keyofAndIndexedAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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;
}
28 changes: 28 additions & 0 deletions tests/baselines/reference/keyofAndIndexedAccess.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

28 changes: 28 additions & 0 deletions tests/baselines/reference/keyofAndIndexedAccess.types
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

12 changes: 12 additions & 0 deletions tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}