diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 60d109d7600e3..bd8ff7568f350 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4871,7 +4871,7 @@ namespace ts { */ function getApparentType(type: Type): Type { const t = type.flags & TypeFlags.TypeVariable ? getBaseConstraintOfType(type) || emptyObjectType : type; - return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(type) : + return t.flags & TypeFlags.Intersection ? getApparentTypeOfIntersectionType(t) : t.flags & TypeFlags.StringLike ? globalStringType : t.flags & TypeFlags.NumberLike ? globalNumberType : t.flags & TypeFlags.BooleanLike ? globalBooleanType : diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index a86184c8ff0f9..e7df8bbd5a1d1 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -504,6 +504,18 @@ function updateIds2( // Repro from #13514 declare function head>(list: T): T[0]; + +// Repro from #13604 + +class A { + 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>(list: T): T[0]; +declare class A { + props: T & { + foo: string; + }; +} +declare class B extends A<{ + x: number; +}> { + f(p: this["props"]): void; +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 4c12c6554c995..01501cd719c91 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -1816,3 +1816,31 @@ declare function head>(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 { +>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)) + } +} + diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 3919d76815102..21c9d645ce4d9 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -2138,3 +2138,31 @@ declare function head>(list: T): T[0]; >T : T >T : T +// Repro from #13604 + +class A { +>A : A +>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 + } +} + diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index a4088e65df42f..04c26fbe8f73e 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -505,3 +505,15 @@ function updateIds2( // Repro from #13514 declare function head>(list: T): T[0]; + +// Repro from #13604 + +class A { + props: T & { foo: string }; +} + +class B extends A<{ x: number}> { + f(p: this["props"]) { + p.x; + } +}