Skip to content

Commit 4b7441a

Browse files
🤖 Pick PR #60680 (Mark the inherited any-based index ...) into release-5.7 (#60776)
Co-authored-by: Wesley Wigham <[email protected]>
1 parent e844dc3 commit 4b7441a

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

Diff for: ‎src/compiler/checker.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
21502150
var silentNeverSignature = createSignature(/*declaration*/ undefined, /*typeParameters*/ undefined, /*thisParameter*/ undefined, emptyArray, silentNeverType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None);
21512151

21522152
var enumNumberIndexInfo = createIndexInfo(numberType, stringType, /*isReadonly*/ true);
2153+
var anyBaseTypeIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false);
21532154

21542155
var iterationTypesCache = new Map<string, IterationTypes>(); // cache for common IterationTypes instances
21552156
var noIterationTypes: IterationTypes = {
@@ -13385,7 +13386,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1338513386
addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType));
1338613387
callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call));
1338713388
constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct));
13388-
const inheritedIndexInfos = instantiatedBaseType !== anyType ? getIndexInfosOfType(instantiatedBaseType) : [createIndexInfo(stringType, anyType, /*isReadonly*/ false)];
13389+
const inheritedIndexInfos = instantiatedBaseType !== anyType ? getIndexInfosOfType(instantiatedBaseType) : [anyBaseTypeIndexInfo];
1338913390
indexInfos = concatenate(indexInfos, filter(inheritedIndexInfos, info => !findIndexInfo(indexInfos, info.keyType)));
1339013391
}
1339113392
}
@@ -13917,7 +13918,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1391713918
addInheritedMembers(members, getPropertiesOfType(baseConstructorType));
1391813919
}
1391913920
else if (baseConstructorType === anyType) {
13920-
baseConstructorIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false);
13921+
baseConstructorIndexInfo = anyBaseTypeIndexInfo;
1392113922
}
1392213923
}
1392313924

@@ -50345,6 +50346,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
5034550346
result ||= [];
5034650347
for (const info of infoList!) {
5034750348
if (info.declaration) continue;
50349+
if (info === anyBaseTypeIndexInfo) continue; // inherited, but looks like a late-bound signature because it has no declarations
5034850350
const node = nodeBuilder.indexInfoToIndexSignatureDeclaration(info, enclosing, flags, internalFlags, tracker);
5034950351
if (node && infoList === staticInfos) {
5035050352
(((node as Mutable<typeof node>).modifiers ||= factory.createNodeArray()) as MutableNodeArray<Modifier>).unshift(factory.createModifier(SyntaxKind.StaticKeyword));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//// [tests/cases/compiler/declarationEmitClassInherritsAny.ts] ////
2+
3+
//// [declarationEmitClassInherritsAny.ts]
4+
const anyThing = class {} as any;
5+
export class Foo extends anyThing {}
6+
7+
//// [declarationEmitClassInherritsAny.js]
8+
"use strict";
9+
var __extends = (this && this.__extends) || (function () {
10+
var extendStatics = function (d, b) {
11+
extendStatics = Object.setPrototypeOf ||
12+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
13+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
14+
return extendStatics(d, b);
15+
};
16+
return function (d, b) {
17+
if (typeof b !== "function" && b !== null)
18+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
19+
extendStatics(d, b);
20+
function __() { this.constructor = d; }
21+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22+
};
23+
})();
24+
Object.defineProperty(exports, "__esModule", { value: true });
25+
exports.Foo = void 0;
26+
var anyThing = /** @class */ (function () {
27+
function class_1() {
28+
}
29+
return class_1;
30+
}());
31+
var Foo = /** @class */ (function (_super) {
32+
__extends(Foo, _super);
33+
function Foo() {
34+
return _super !== null && _super.apply(this, arguments) || this;
35+
}
36+
return Foo;
37+
}(anyThing));
38+
exports.Foo = Foo;
39+
40+
41+
//// [declarationEmitClassInherritsAny.d.ts]
42+
declare const anyThing: any;
43+
export declare class Foo extends anyThing {
44+
}
45+
export {};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [tests/cases/compiler/declarationEmitClassInherritsAny.ts] ////
2+
3+
=== declarationEmitClassInherritsAny.ts ===
4+
const anyThing = class {} as any;
5+
>anyThing : Symbol(anyThing, Decl(declarationEmitClassInherritsAny.ts, 0, 5))
6+
7+
export class Foo extends anyThing {}
8+
>Foo : Symbol(Foo, Decl(declarationEmitClassInherritsAny.ts, 0, 33))
9+
>anyThing : Symbol(anyThing, Decl(declarationEmitClassInherritsAny.ts, 0, 5))
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/declarationEmitClassInherritsAny.ts] ////
2+
3+
=== declarationEmitClassInherritsAny.ts ===
4+
const anyThing = class {} as any;
5+
>anyThing : any
6+
>class {} as any : any
7+
>class {} : typeof (Anonymous class)
8+
> : ^^^^^^^^^^^^^^^^^^^^^^^^
9+
10+
export class Foo extends anyThing {}
11+
>Foo : Foo
12+
> : ^^^
13+
>anyThing : any
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @declaration: true
2+
const anyThing = class {} as any;
3+
export class Foo extends anyThing {}

0 commit comments

Comments
 (0)