Skip to content

Commit 8456dcc

Browse files
Directly copy only the index signature in addition to declared properties (#56626)
1 parent fc30163 commit 8456dcc

6 files changed

+351
-6
lines changed

src/compiler/checker.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -13060,12 +13060,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1306013060
const baseTypes = getBaseTypes(source);
1306113061
if (baseTypes.length) {
1306213062
if (source.symbol && members === getMembersOfSymbol(source.symbol)) {
13063-
const symbolTable = createSymbolTable();
13064-
// copy all symbols (except type parameters), including the ones with internal names like `InternalSymbolName.Index`
13065-
for (const symbol of members.values()) {
13066-
if (!(symbol.flags & SymbolFlags.TypeParameter)) {
13067-
symbolTable.set(symbol.escapedName, symbol);
13068-
}
13063+
const symbolTable = createSymbolTable(source.declaredProperties);
13064+
// copy index signature symbol as well (for quickinfo)
13065+
const sourceIndex = getIndexSymbol(source.symbol);
13066+
if (sourceIndex) {
13067+
symbolTable.set(InternalSymbolName.Index, sourceIndex);
1306913068
}
1307013069
members = symbolTable;
1307113070
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
conflictingTypeParameterSymbolTransfer.ts(13,16): error TS2304: Cannot find name 'U'.
2+
3+
4+
==== conflictingTypeParameterSymbolTransfer.ts (1 errors) ====
5+
// @strict
6+
7+
// Via #56620
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+
!!! error TS2304: Cannot find name 'U'.
20+
}
21+
}
22+
23+
// via #56689
24+
class Leg { }
25+
class Foo<t> extends Leg {
26+
t = {} as t
27+
28+
// should allow this access since t was declared as a property on Foo
29+
foo = this.t
30+
}
31+
32+
// via #56661
33+
class BaseClass { }
34+
class Item<data> extends BaseClass {
35+
data: data;
36+
getData() {
37+
// should OK
38+
return this.data;
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//// [tests/cases/compiler/conflictingTypeParameterSymbolTransfer.ts] ////
2+
3+
//// [conflictingTypeParameterSymbolTransfer.ts]
4+
// @strict
5+
6+
// Via #56620
7+
class Base<U> { }
8+
export class C2<T> extends Base<unknown> {
9+
T: number;
10+
constructor(T: number) {
11+
super();
12+
// Should not error
13+
this.T = T;
14+
15+
// Should error
16+
let a: U = null;
17+
}
18+
}
19+
20+
// via #56689
21+
class Leg { }
22+
class Foo<t> extends Leg {
23+
t = {} as t
24+
25+
// should allow this access since t was declared as a property on Foo
26+
foo = this.t
27+
}
28+
29+
// via #56661
30+
class BaseClass { }
31+
class Item<data> extends BaseClass {
32+
data: data;
33+
getData() {
34+
// should OK
35+
return this.data;
36+
}
37+
}
38+
39+
//// [conflictingTypeParameterSymbolTransfer.js]
40+
"use strict";
41+
// @strict
42+
var __extends = (this && this.__extends) || (function () {
43+
var extendStatics = function (d, b) {
44+
extendStatics = Object.setPrototypeOf ||
45+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
46+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
47+
return extendStatics(d, b);
48+
};
49+
return function (d, b) {
50+
if (typeof b !== "function" && b !== null)
51+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
52+
extendStatics(d, b);
53+
function __() { this.constructor = d; }
54+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
55+
};
56+
})();
57+
Object.defineProperty(exports, "__esModule", { value: true });
58+
exports.C2 = void 0;
59+
// Via #56620
60+
var Base = /** @class */ (function () {
61+
function Base() {
62+
}
63+
return Base;
64+
}());
65+
var C2 = /** @class */ (function (_super) {
66+
__extends(C2, _super);
67+
function C2(T) {
68+
var _this = _super.call(this) || this;
69+
// Should not error
70+
_this.T = T;
71+
// Should error
72+
var a = null;
73+
return _this;
74+
}
75+
return C2;
76+
}(Base));
77+
exports.C2 = C2;
78+
// via #56689
79+
var Leg = /** @class */ (function () {
80+
function Leg() {
81+
}
82+
return Leg;
83+
}());
84+
var Foo = /** @class */ (function (_super) {
85+
__extends(Foo, _super);
86+
function Foo() {
87+
var _this = _super !== null && _super.apply(this, arguments) || this;
88+
_this.t = {};
89+
// should allow this access since t was declared as a property on Foo
90+
_this.foo = _this.t;
91+
return _this;
92+
}
93+
return Foo;
94+
}(Leg));
95+
// via #56661
96+
var BaseClass = /** @class */ (function () {
97+
function BaseClass() {
98+
}
99+
return BaseClass;
100+
}());
101+
var Item = /** @class */ (function (_super) {
102+
__extends(Item, _super);
103+
function Item() {
104+
return _super !== null && _super.apply(this, arguments) || this;
105+
}
106+
Item.prototype.getData = function () {
107+
// should OK
108+
return this.data;
109+
};
110+
return Item;
111+
}(BaseClass));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//// [tests/cases/compiler/conflictingTypeParameterSymbolTransfer.ts] ////
2+
3+
=== conflictingTypeParameterSymbolTransfer.ts ===
4+
// @strict
5+
6+
// Via #56620
7+
class Base<U> { }
8+
>Base : Symbol(Base, Decl(conflictingTypeParameterSymbolTransfer.ts, 0, 0))
9+
>U : Symbol(U, Decl(conflictingTypeParameterSymbolTransfer.ts, 3, 11))
10+
11+
export class C2<T> extends Base<unknown> {
12+
>C2 : Symbol(C2, Decl(conflictingTypeParameterSymbolTransfer.ts, 3, 17))
13+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 16), Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 42))
14+
>Base : Symbol(Base, Decl(conflictingTypeParameterSymbolTransfer.ts, 0, 0))
15+
16+
T: number;
17+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 16), Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 42))
18+
19+
constructor(T: number) {
20+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 6, 16))
21+
22+
super();
23+
>super : Symbol(Base, Decl(conflictingTypeParameterSymbolTransfer.ts, 0, 0))
24+
25+
// Should not error
26+
this.T = T;
27+
>this.T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 16), Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 42))
28+
>this : Symbol(C2, Decl(conflictingTypeParameterSymbolTransfer.ts, 3, 17))
29+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 16), Decl(conflictingTypeParameterSymbolTransfer.ts, 4, 42))
30+
>T : Symbol(T, Decl(conflictingTypeParameterSymbolTransfer.ts, 6, 16))
31+
32+
// Should error
33+
let a: U = null;
34+
>a : Symbol(a, Decl(conflictingTypeParameterSymbolTransfer.ts, 12, 11))
35+
>U : Symbol(U)
36+
}
37+
}
38+
39+
// via #56689
40+
class Leg { }
41+
>Leg : Symbol(Leg, Decl(conflictingTypeParameterSymbolTransfer.ts, 14, 1))
42+
43+
class Foo<t> extends Leg {
44+
>Foo : Symbol(Foo, Decl(conflictingTypeParameterSymbolTransfer.ts, 17, 13))
45+
>t : Symbol(t, Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 10), Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 26))
46+
>Leg : Symbol(Leg, Decl(conflictingTypeParameterSymbolTransfer.ts, 14, 1))
47+
48+
t = {} as t
49+
>t : Symbol(t, Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 10), Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 26))
50+
>t : Symbol(t, Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 10), Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 26))
51+
52+
// should allow this access since t was declared as a property on Foo
53+
foo = this.t
54+
>foo : Symbol(Foo.foo, Decl(conflictingTypeParameterSymbolTransfer.ts, 19, 15))
55+
>this.t : Symbol(t, Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 10), Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 26))
56+
>this : Symbol(Foo, Decl(conflictingTypeParameterSymbolTransfer.ts, 17, 13))
57+
>t : Symbol(t, Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 10), Decl(conflictingTypeParameterSymbolTransfer.ts, 18, 26))
58+
}
59+
60+
// via #56661
61+
class BaseClass { }
62+
>BaseClass : Symbol(BaseClass, Decl(conflictingTypeParameterSymbolTransfer.ts, 23, 1))
63+
64+
class Item<data> extends BaseClass {
65+
>Item : Symbol(Item, Decl(conflictingTypeParameterSymbolTransfer.ts, 26, 19))
66+
>data : Symbol(data, Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 11), Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 36))
67+
>BaseClass : Symbol(BaseClass, Decl(conflictingTypeParameterSymbolTransfer.ts, 23, 1))
68+
69+
data: data;
70+
>data : Symbol(data, Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 11), Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 36))
71+
>data : Symbol(data, Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 11), Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 36))
72+
73+
getData() {
74+
>getData : Symbol(Item.getData, Decl(conflictingTypeParameterSymbolTransfer.ts, 28, 15))
75+
76+
// should OK
77+
return this.data;
78+
>this.data : Symbol(data, Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 11), Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 36))
79+
>this : Symbol(Item, Decl(conflictingTypeParameterSymbolTransfer.ts, 26, 19))
80+
>data : Symbol(data, Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 11), Decl(conflictingTypeParameterSymbolTransfer.ts, 27, 36))
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//// [tests/cases/compiler/conflictingTypeParameterSymbolTransfer.ts] ////
2+
3+
=== conflictingTypeParameterSymbolTransfer.ts ===
4+
// @strict
5+
6+
// Via #56620
7+
class Base<U> { }
8+
>Base : Base<U>
9+
10+
export class C2<T> extends Base<unknown> {
11+
>C2 : C2<T>
12+
>Base : Base<unknown>
13+
14+
T: number;
15+
>T : number
16+
17+
constructor(T: number) {
18+
>T : number
19+
20+
super();
21+
>super() : void
22+
>super : typeof Base
23+
24+
// Should not error
25+
this.T = T;
26+
>this.T = T : number
27+
>this.T : number
28+
>this : this
29+
>T : number
30+
>T : number
31+
32+
// Should error
33+
let a: U = null;
34+
>a : U
35+
}
36+
}
37+
38+
// via #56689
39+
class Leg { }
40+
>Leg : Leg
41+
42+
class Foo<t> extends Leg {
43+
>Foo : Foo<t>
44+
>Leg : Leg
45+
46+
t = {} as t
47+
>t : t
48+
>{} as t : t
49+
>{} : {}
50+
51+
// should allow this access since t was declared as a property on Foo
52+
foo = this.t
53+
>foo : t
54+
>this.t : t
55+
>this : this
56+
>t : t
57+
}
58+
59+
// via #56661
60+
class BaseClass { }
61+
>BaseClass : BaseClass
62+
63+
class Item<data> extends BaseClass {
64+
>Item : Item<data>
65+
>BaseClass : BaseClass
66+
67+
data: data;
68+
>data : data
69+
70+
getData() {
71+
>getData : () => data
72+
73+
// should OK
74+
return this.data;
75+
>this.data : data
76+
>this : this
77+
>data : data
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @strict
2+
3+
// Via #56620
4+
class Base<U> { }
5+
export class C2<T> extends Base<unknown> {
6+
T: number;
7+
constructor(T: number) {
8+
super();
9+
// Should not error
10+
this.T = T;
11+
12+
// Should error
13+
let a: U = null;
14+
}
15+
}
16+
17+
// via #56689
18+
class Leg { }
19+
class Foo<t> extends Leg {
20+
t = {} as t
21+
22+
// should allow this access since t was declared as a property on Foo
23+
foo = this.t
24+
}
25+
26+
// via #56661
27+
class BaseClass { }
28+
class Item<data> extends BaseClass {
29+
data: data;
30+
getData() {
31+
// should OK
32+
return this.data;
33+
}
34+
}

0 commit comments

Comments
 (0)