Skip to content

Commit 3cf326a

Browse files
authored
Merge pull request #13623 from Microsoft/fixIntersectionApparentType
Fix intersection apparent type
2 parents 5b9004e + f0e90c0 commit 3cf326a

File tree

5 files changed

+107
-1
lines changed

5 files changed

+107
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4871,7 +4871,7 @@ namespace ts {
48714871
*/
48724872
function getApparentType(type: Type): Type {
48734873
const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(<TypeVariable>type) || emptyObjectType : type;
4874-
return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>type) :
4874+
return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(<IntersectionType>t) :
48754875
t.flags & TypeFlags.StringLike ? globalStringType :
48764876
t.flags & TypeFlags.NumberLike ? globalNumberType :
48774877
t.flags & TypeFlags.BooleanLike ? globalBooleanType :

tests/baselines/reference/keyofAndIndexedAccess.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@ function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
504504
// Repro from #13514
505505

506506
declare function head<T extends Array<any>>(list: T): T[0];
507+
508+
// Repro from #13604
509+
510+
class A<T> {
511+
props: T & { foo: string };
512+
}
513+
514+
class B extends A<{ x: number}> {
515+
f(p: this["props"]) {
516+
p.x;
517+
}
518+
}
507519

508520

509521
//// [keyofAndIndexedAccess.js]
@@ -834,6 +846,22 @@ function updateIds2(obj, key, stringMap) {
834846
var x = obj[key];
835847
stringMap[x]; // Should be OK.
836848
}
849+
// Repro from #13604
850+
var A = (function () {
851+
function A() {
852+
}
853+
return A;
854+
}());
855+
var B = (function (_super) {
856+
__extends(B, _super);
857+
function B() {
858+
return _super !== null && _super.apply(this, arguments) || this;
859+
}
860+
B.prototype.f = function (p) {
861+
p.x;
862+
};
863+
return B;
864+
}(A));
837865

838866

839867
//// [keyofAndIndexedAccess.d.ts]
@@ -1066,3 +1094,13 @@ declare function updateIds2<T extends {
10661094
[oldId: string]: string;
10671095
}): void;
10681096
declare function head<T extends Array<any>>(list: T): T[0];
1097+
declare class A<T> {
1098+
props: T & {
1099+
foo: string;
1100+
};
1101+
}
1102+
declare class B extends A<{
1103+
x: number;
1104+
}> {
1105+
f(p: this["props"]): void;
1106+
}

tests/baselines/reference/keyofAndIndexedAccess.symbols

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,3 +1816,31 @@ declare function head<T extends Array<any>>(list: T): T[0];
18161816
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 504, 22))
18171817
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 504, 22))
18181818

1819+
// Repro from #13604
1820+
1821+
class A<T> {
1822+
>A : Symbol(A, Decl(keyofAndIndexedAccess.ts, 504, 59))
1823+
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 508, 8))
1824+
1825+
props: T & { foo: string };
1826+
>props : Symbol(A.props, Decl(keyofAndIndexedAccess.ts, 508, 12))
1827+
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 508, 8))
1828+
>foo : Symbol(foo, Decl(keyofAndIndexedAccess.ts, 509, 13))
1829+
}
1830+
1831+
class B extends A<{ x: number}> {
1832+
>B : Symbol(B, Decl(keyofAndIndexedAccess.ts, 510, 1))
1833+
>A : Symbol(A, Decl(keyofAndIndexedAccess.ts, 504, 59))
1834+
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 512, 19))
1835+
1836+
f(p: this["props"]) {
1837+
>f : Symbol(B.f, Decl(keyofAndIndexedAccess.ts, 512, 33))
1838+
>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 513, 3))
1839+
1840+
p.x;
1841+
>p.x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 512, 19))
1842+
>p : Symbol(p, Decl(keyofAndIndexedAccess.ts, 513, 3))
1843+
>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 512, 19))
1844+
}
1845+
}
1846+

tests/baselines/reference/keyofAndIndexedAccess.types

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,3 +2138,31 @@ declare function head<T extends Array<any>>(list: T): T[0];
21382138
>T : T
21392139
>T : T
21402140

2141+
// Repro from #13604
2142+
2143+
class A<T> {
2144+
>A : A<T>
2145+
>T : T
2146+
2147+
props: T & { foo: string };
2148+
>props : T & { foo: string; }
2149+
>T : T
2150+
>foo : string
2151+
}
2152+
2153+
class B extends A<{ x: number}> {
2154+
>B : B
2155+
>A : A<{ x: number; }>
2156+
>x : number
2157+
2158+
f(p: this["props"]) {
2159+
>f : (p: this["props"]) => void
2160+
>p : this["props"]
2161+
2162+
p.x;
2163+
>p.x : number
2164+
>p : this["props"]
2165+
>x : number
2166+
}
2167+
}
2168+

tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,15 @@ function updateIds2<T extends { [x: string]: string }, K extends keyof T>(
505505
// Repro from #13514
506506

507507
declare function head<T extends Array<any>>(list: T): T[0];
508+
509+
// Repro from #13604
510+
511+
class A<T> {
512+
props: T & { foo: string };
513+
}
514+
515+
class B extends A<{ x: number}> {
516+
f(p: this["props"]) {
517+
p.x;
518+
}
519+
}

0 commit comments

Comments
 (0)