Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Pick PR #60680 (Mark the inherited any-based index ...) into release-5.7 #60776

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
var silentNeverSignature = createSignature(/*declaration*/ undefined, /*typeParameters*/ undefined, /*thisParameter*/ undefined, emptyArray, silentNeverType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None);

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

var iterationTypesCache = new Map<string, IterationTypes>(); // cache for common IterationTypes instances
var noIterationTypes: IterationTypes = {
Expand Down Expand Up @@ -13385,7 +13386,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType));
callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call));
constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct));
const inheritedIndexInfos = instantiatedBaseType !== anyType ? getIndexInfosOfType(instantiatedBaseType) : [createIndexInfo(stringType, anyType, /*isReadonly*/ false)];
const inheritedIndexInfos = instantiatedBaseType !== anyType ? getIndexInfosOfType(instantiatedBaseType) : [anyBaseTypeIndexInfo];
indexInfos = concatenate(indexInfos, filter(inheritedIndexInfos, info => !findIndexInfo(indexInfos, info.keyType)));
}
}
Expand Down Expand Up @@ -13917,7 +13918,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
addInheritedMembers(members, getPropertiesOfType(baseConstructorType));
}
else if (baseConstructorType === anyType) {
baseConstructorIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false);
baseConstructorIndexInfo = anyBaseTypeIndexInfo;
}
}

Expand Down Expand Up @@ -50341,6 +50342,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
result ||= [];
for (const info of infoList!) {
if (info.declaration) continue;
if (info === anyBaseTypeIndexInfo) continue; // inherited, but looks like a late-bound signature because it has no declarations
const node = nodeBuilder.indexInfoToIndexSignatureDeclaration(info, enclosing, flags, internalFlags, tracker);
if (node && infoList === staticInfos) {
(((node as Mutable<typeof node>).modifiers ||= factory.createNodeArray()) as MutableNodeArray<Modifier>).unshift(factory.createModifier(SyntaxKind.StaticKeyword));
Expand Down
45 changes: 45 additions & 0 deletions tests/baselines/reference/declarationEmitClassInherritsAny.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//// [tests/cases/compiler/declarationEmitClassInherritsAny.ts] ////

//// [declarationEmitClassInherritsAny.ts]
const anyThing = class {} as any;
export class Foo extends anyThing {}

//// [declarationEmitClassInherritsAny.js]
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Foo = void 0;
var anyThing = /** @class */ (function () {
function class_1() {
}
return class_1;
}());
var Foo = /** @class */ (function (_super) {
__extends(Foo, _super);
function Foo() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Foo;
}(anyThing));
exports.Foo = Foo;


//// [declarationEmitClassInherritsAny.d.ts]
declare const anyThing: any;
export declare class Foo extends anyThing {
}
export {};
10 changes: 10 additions & 0 deletions tests/baselines/reference/declarationEmitClassInherritsAny.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//// [tests/cases/compiler/declarationEmitClassInherritsAny.ts] ////

=== declarationEmitClassInherritsAny.ts ===
const anyThing = class {} as any;
>anyThing : Symbol(anyThing, Decl(declarationEmitClassInherritsAny.ts, 0, 5))

export class Foo extends anyThing {}
>Foo : Symbol(Foo, Decl(declarationEmitClassInherritsAny.ts, 0, 33))
>anyThing : Symbol(anyThing, Decl(declarationEmitClassInherritsAny.ts, 0, 5))

14 changes: 14 additions & 0 deletions tests/baselines/reference/declarationEmitClassInherritsAny.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [tests/cases/compiler/declarationEmitClassInherritsAny.ts] ////

=== declarationEmitClassInherritsAny.ts ===
const anyThing = class {} as any;
>anyThing : any
>class {} as any : any
>class {} : typeof (Anonymous class)
> : ^^^^^^^^^^^^^^^^^^^^^^^^

export class Foo extends anyThing {}
>Foo : Foo
> : ^^^
>anyThing : any

3 changes: 3 additions & 0 deletions tests/cases/compiler/declarationEmitClassInherritsAny.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @declaration: true
const anyThing = class {} as any;
export class Foo extends anyThing {}
Loading