Skip to content

Commit a47b73b

Browse files
committed
Directly copy only the index signature in addition to declared properties
Fixes microsoft#56620 Partial revert of microsoft#55252
1 parent 8d1fa44 commit a47b73b

6 files changed

+181
-6
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13058,12 +13058,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1305813058
const baseTypes = getBaseTypes(source);
1305913059
if (baseTypes.length) {
1306013060
if (source.symbol && members === getMembersOfSymbol(source.symbol)) {
13061-
const symbolTable = createSymbolTable();
13062-
// copy all symbols (except type parameters), including the ones with internal names like `InternalSymbolName.Index`
13063-
for (const symbol of members.values()) {
13064-
if (!(symbol.flags & SymbolFlags.TypeParameter)) {
13065-
symbolTable.set(symbol.escapedName, symbol);
13066-
}
13061+
const symbolTable = createSymbolTable(source.declaredProperties);
13062+
// copy index signature symbol as well (for quickinfo)
13063+
const sourceIndex = getIndexSymbol(source.symbol);
13064+
if (sourceIndex) {
13065+
symbolTable.set(InternalSymbolName.Index, sourceIndex);
1306713066
}
1306813067
members = symbolTable;
1306913068
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
conflictingTypeParameterSymbolTransfer.ts(14,16): error TS2304: Cannot find name 'U'.
2+
3+
4+
==== conflictingTypeParameterSymbolTransfer.ts (1 errors) ====
5+
// @strict
6+
7+
// Via #56620
8+
9+
class Base<U> { }
10+
export class C2<T> extends Base<unknown> {
11+
T: number;
12+
constructor(T: number) {
13+
super();
14+
// Should not error
15+
this.T = T;
16+
17+
// Should error
18+
let a: U = null;
19+
~
20+
!!! error TS2304: Cannot find name 'U'.
21+
}
22+
}
23+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//// [tests/cases/compiler/conflictingTypeParameterSymbolTransfer.ts] ////
2+
3+
//// [conflictingTypeParameterSymbolTransfer.ts]
4+
// @strict
5+
6+
// Via #56620
7+
8+
class Base<U> { }
9+
export class C2<T> extends Base<unknown> {
10+
T: number;
11+
constructor(T: number) {
12+
super();
13+
// Should not error
14+
this.T = T;
15+
16+
// Should error
17+
let a: U = null;
18+
}
19+
}
20+
21+
22+
//// [conflictingTypeParameterSymbolTransfer.js]
23+
"use strict";
24+
// @strict
25+
var __extends = (this && this.__extends) || (function () {
26+
var extendStatics = function (d, b) {
27+
extendStatics = Object.setPrototypeOf ||
28+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
29+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
30+
return extendStatics(d, b);
31+
};
32+
return function (d, b) {
33+
if (typeof b !== "function" && b !== null)
34+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
35+
extendStatics(d, b);
36+
function __() { this.constructor = d; }
37+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
38+
};
39+
})();
40+
Object.defineProperty(exports, "__esModule", { value: true });
41+
exports.C2 = void 0;
42+
// Via #56620
43+
var Base = /** @class */ (function () {
44+
function Base() {
45+
}
46+
return Base;
47+
}());
48+
var C2 = /** @class */ (function (_super) {
49+
__extends(C2, _super);
50+
function C2(T) {
51+
var _this = _super.call(this) || this;
52+
// Should not error
53+
_this.T = T;
54+
// Should error
55+
var a = null;
56+
return _this;
57+
}
58+
return C2;
59+
}(Base));
60+
exports.C2 = C2;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//// [tests/cases/compiler/conflictingTypeParameterSymbolTransfer.ts] ////
2+
3+
=== conflictingTypeParameterSymbolTransfer.ts ===
4+
// @strict
5+
6+
// Via #56620
7+
8+
class Base<U> { }
9+
>Base : Symbol(Base, Decl(conflictingTypeParameterSymbolTransfer.ts, 0, 0))
10+
>U : Symbol(U, Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 11))
11+
12+
export class C2<T> extends Base<unknown> {
13+
>C2 : Symbol(C2, Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 17))
14+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 5, 16), Decl(conflictingTypeParameterSymbolTransfer.ts, 5, 42))
15+
>Base : Symbol(Base, Decl(conflictingTypeParameterSymbolTransfer.ts, 0, 0))
16+
17+
T: number;
18+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 5, 16), Decl(conflictingTypeParameterSymbolTransfer.ts, 5, 42))
19+
20+
constructor(T: number) {
21+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 7, 16))
22+
23+
super();
24+
>super : Symbol(Base, Decl(conflictingTypeParameterSymbolTransfer.ts, 0, 0))
25+
26+
// Should not error
27+
this.T = T;
28+
>this.T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 5, 16), Decl(conflictingTypeParameterSymbolTransfer.ts, 5, 42))
29+
>this : Symbol(C2, Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 17))
30+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 5, 16), Decl(conflictingTypeParameterSymbolTransfer.ts, 5, 42))
31+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 7, 16))
32+
33+
// Should error
34+
let a: U = null;
35+
>a : Symbol(a, Decl(conflictingTypeParameterSymbolTransfer.ts, 13, 11))
36+
>U : Symbol(U)
37+
}
38+
}
39+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [tests/cases/compiler/conflictingTypeParameterSymbolTransfer.ts] ////
2+
3+
=== conflictingTypeParameterSymbolTransfer.ts ===
4+
// @strict
5+
6+
// Via #56620
7+
8+
class Base<U> { }
9+
>Base : Base<U>
10+
11+
export class C2<T> extends Base<unknown> {
12+
>C2 : C2<T>
13+
>Base : Base<unknown>
14+
15+
T: number;
16+
>T : number
17+
18+
constructor(T: number) {
19+
>T : number
20+
21+
super();
22+
>super() : void
23+
>super : typeof Base
24+
25+
// Should not error
26+
this.T = T;
27+
>this.T = T : number
28+
>this.T : number
29+
>this : this
30+
>T : number
31+
>T : number
32+
33+
// Should error
34+
let a: U = null;
35+
>a : U
36+
}
37+
}
38+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @strict
2+
3+
// Via #56620
4+
5+
class Base<U> { }
6+
export class C2<T> extends Base<unknown> {
7+
T: number;
8+
constructor(T: number) {
9+
super();
10+
// Should not error
11+
this.T = T;
12+
13+
// Should error
14+
let a: U = null;
15+
}
16+
}

0 commit comments

Comments
 (0)