From 4b7441a8bee1f0cbc861a3ad23f72769fb518df1 Mon Sep 17 00:00:00 2001 From: TypeScript Bot <23042052+typescript-bot@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:26:58 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#60680=20(Mark=20the?= =?UTF-8?q?=20inherited=20any-based=20index=20...)=20into=20release-5.7=20?= =?UTF-8?q?(#60776)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Wesley Wigham --- src/compiler/checker.ts | 6 ++- .../declarationEmitClassInherritsAny.js | 45 +++++++++++++++++++ .../declarationEmitClassInherritsAny.symbols | 10 +++++ .../declarationEmitClassInherritsAny.types | 14 ++++++ .../declarationEmitClassInherritsAny.ts | 3 ++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitClassInherritsAny.js create mode 100644 tests/baselines/reference/declarationEmitClassInherritsAny.symbols create mode 100644 tests/baselines/reference/declarationEmitClassInherritsAny.types create mode 100644 tests/cases/compiler/declarationEmitClassInherritsAny.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9aa454547e3d9..df45bdc1a6008 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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(); // cache for common IterationTypes instances var noIterationTypes: IterationTypes = { @@ -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))); } } @@ -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; } } @@ -50345,6 +50346,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).modifiers ||= factory.createNodeArray()) as MutableNodeArray).unshift(factory.createModifier(SyntaxKind.StaticKeyword)); diff --git a/tests/baselines/reference/declarationEmitClassInherritsAny.js b/tests/baselines/reference/declarationEmitClassInherritsAny.js new file mode 100644 index 0000000000000..8c4103422b2e9 --- /dev/null +++ b/tests/baselines/reference/declarationEmitClassInherritsAny.js @@ -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 {}; diff --git a/tests/baselines/reference/declarationEmitClassInherritsAny.symbols b/tests/baselines/reference/declarationEmitClassInherritsAny.symbols new file mode 100644 index 0000000000000..81b11da2ee0b7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitClassInherritsAny.symbols @@ -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)) + diff --git a/tests/baselines/reference/declarationEmitClassInherritsAny.types b/tests/baselines/reference/declarationEmitClassInherritsAny.types new file mode 100644 index 0000000000000..39d65e433f824 --- /dev/null +++ b/tests/baselines/reference/declarationEmitClassInherritsAny.types @@ -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 + diff --git a/tests/cases/compiler/declarationEmitClassInherritsAny.ts b/tests/cases/compiler/declarationEmitClassInherritsAny.ts new file mode 100644 index 0000000000000..7749e21320c14 --- /dev/null +++ b/tests/cases/compiler/declarationEmitClassInherritsAny.ts @@ -0,0 +1,3 @@ +// @declaration: true +const anyThing = class {} as any; +export class Foo extends anyThing {} \ No newline at end of file