Skip to content

Commit

Permalink
🤖 Pick PR #60680 (Mark the inherited any-based index ...) into releas…
Browse files Browse the repository at this point in the history
…e-5.7 (#60776)

Co-authored-by: Wesley Wigham <[email protected]>
  • Loading branch information
typescript-bot and weswigham authored Dec 17, 2024
1 parent e844dc3 commit 4b7441a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
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 @@ -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<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 {}

0 comments on commit 4b7441a

Please sign in to comment.