From 9cbcf010ce0701a25f01a2a074000db34f80cc17 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:25:10 -0700 Subject: [PATCH] Ensure generated property names for methods named "new" are quoted (#55750) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mateusz BurzyƄski --- src/compiler/checker.ts | 9 ++-- src/compiler/utilities.ts | 7 +-- src/services/codefixes/fixAddMissingMember.ts | 3 +- .../reference/emitMethodCalledNew.js | 43 +++++++++++++++++++ .../reference/emitMethodCalledNew.symbols | 31 +++++++++++++ .../reference/emitMethodCalledNew.types | 40 +++++++++++++++++ ...ypesIdentityWithConstructSignatures2.types | 34 +++++++-------- ...structSignaturesDifferingParamCounts.types | 34 +++++++-------- ...ructSignaturesDifferingByConstraints.types | 34 +++++++-------- ...uctSignaturesDifferingByConstraints2.types | 34 +++++++-------- ...uctSignaturesDifferingByConstraints3.types | 34 +++++++-------- ...tructSignaturesDifferingByReturnType.types | 42 +++++++++--------- ...ructSignaturesDifferingByReturnType2.types | 34 +++++++-------- ...gnaturesDifferingTypeParameterCounts.types | 34 +++++++-------- ...ignaturesDifferingTypeParameterNames.types | 34 +++++++-------- ...ricConstructSignaturesOptionalParams.types | 34 +++++++-------- ...icConstructSignaturesOptionalParams2.types | 34 +++++++-------- ...icConstructSignaturesOptionalParams3.types | 34 +++++++-------- tests/baselines/reference/parser645484.types | 2 +- tests/baselines/reference/vardecl.types | 2 +- tests/cases/compiler/emitMethodCalledNew.ts | 13 ++++++ .../fourslash/codeFixAddMissingMember31.ts | 17 ++++++++ 22 files changed, 365 insertions(+), 218 deletions(-) create mode 100644 tests/baselines/reference/emitMethodCalledNew.js create mode 100644 tests/baselines/reference/emitMethodCalledNew.symbols create mode 100644 tests/baselines/reference/emitMethodCalledNew.types create mode 100644 tests/cases/compiler/emitMethodCalledNew.ts create mode 100644 tests/cases/fourslash/codeFixAddMissingMember31.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2bae0c73fc42d..ac8e149908a12 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8213,16 +8213,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getPropertyNameNodeForSymbol(symbol: Symbol, context: NodeBuilderContext) { const stringNamed = !!length(symbol.declarations) && every(symbol.declarations, isStringNamed); const singleQuote = !!length(symbol.declarations) && every(symbol.declarations, isSingleQuotedStringNamed); - const fromNameType = getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote, stringNamed); + const isMethod = !!(symbol.flags & SymbolFlags.Method); + const fromNameType = getPropertyNameNodeForSymbolFromNameType(symbol, context, singleQuote, stringNamed, isMethod); if (fromNameType) { return fromNameType; } const rawName = unescapeLeadingUnderscores(symbol.escapedName); - return createPropertyNameNodeForIdentifierOrLiteral(rawName, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed); + return createPropertyNameNodeForIdentifierOrLiteral(rawName, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed, isMethod); } // See getNameForSymbolFromNameType for a stringy equivalent - function getPropertyNameNodeForSymbolFromNameType(symbol: Symbol, context: NodeBuilderContext, singleQuote?: boolean, stringNamed?: boolean) { + function getPropertyNameNodeForSymbolFromNameType(symbol: Symbol, context: NodeBuilderContext, singleQuote: boolean, stringNamed: boolean, isMethod: boolean) { const nameType = getSymbolLinks(symbol).nameType; if (nameType) { if (nameType.flags & TypeFlags.StringOrNumberLiteral) { @@ -8233,7 +8234,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (isNumericLiteralName(name) && startsWith(name, "-")) { return factory.createComputedPropertyName(factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(+name)))); } - return createPropertyNameNodeForIdentifierOrLiteral(name, getEmitScriptTarget(compilerOptions)); + return createPropertyNameNodeForIdentifierOrLiteral(name, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed, isMethod); } if (nameType.flags & TypeFlags.UniqueESSymbol) { return factory.createComputedPropertyName(symbolToExpression((nameType as UniqueESSymbolType).symbol, context, SymbolFlags.Value)); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index cd375d12e759a..4d63c9124a7ac 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -10216,9 +10216,10 @@ export function isNumericLiteralName(name: string | __String) { } /** @internal */ -export function createPropertyNameNodeForIdentifierOrLiteral(name: string, target: ScriptTarget, singleQuote?: boolean, stringNamed?: boolean) { - return isIdentifierText(name, target) ? factory.createIdentifier(name) : - !stringNamed && isNumericLiteralName(name) && +name >= 0 ? factory.createNumericLiteral(+name) : +export function createPropertyNameNodeForIdentifierOrLiteral(name: string, target: ScriptTarget, singleQuote: boolean, stringNamed: boolean, isMethod: boolean) { + const isMethodNamedNew = isMethod && name === "new"; + return !isMethodNamedNew && isIdentifierText(name, target) ? factory.createIdentifier(name) : + !stringNamed && !isMethodNamedNew && isNumericLiteralName(name) && +name >= 0 ? factory.createNumericLiteral(+name) : factory.createStringLiteral(name, !!singleQuote); } diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 90b718fe8437d..3b9340f4e2bf3 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -772,7 +772,8 @@ function createPropertyNameFromSymbol(symbol: Symbol, target: ScriptTarget, quot const prop = checker.symbolToNode(symbol, SymbolFlags.Value, /*enclosingDeclaration*/ undefined, NodeBuilderFlags.WriteComputedProps); if (prop && isComputedPropertyName(prop)) return prop; } - return createPropertyNameNodeForIdentifierOrLiteral(symbol.name, target, quotePreference === QuotePreference.Single); + // We're using these nodes as property names in an object literal; no need to quote names when not needed. + return createPropertyNameNodeForIdentifierOrLiteral(symbol.name, target, quotePreference === QuotePreference.Single, /*stringNamed*/ false, /*isMethod*/ false); } function findScope(node: Node) { diff --git a/tests/baselines/reference/emitMethodCalledNew.js b/tests/baselines/reference/emitMethodCalledNew.js new file mode 100644 index 0000000000000..eec54a1904dd0 --- /dev/null +++ b/tests/baselines/reference/emitMethodCalledNew.js @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/emitMethodCalledNew.ts] //// + +//// [emitMethodCalledNew.ts] +// https://github.com/microsoft/TypeScript/issues/55075 + +export const a = { + new(x: number) { return x + 1 } +} +export const b = { + "new"(x: number) { return x + 1 } +} +export const c = { + ["new"](x: number) { return x + 1 } +} + + +//// [emitMethodCalledNew.js] +"use strict"; +// https://github.com/microsoft/TypeScript/issues/55075 +var _a; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.c = exports.b = exports.a = void 0; +exports.a = { + new: function (x) { return x + 1; } +}; +exports.b = { + "new": function (x) { return x + 1; } +}; +exports.c = (_a = {}, + _a["new"] = function (x) { return x + 1; }, + _a); + + +//// [emitMethodCalledNew.d.ts] +export declare const a: { + "new"(x: number): number; +}; +export declare const b: { + "new"(x: number): number; +}; +export declare const c: { + "new"(x: number): number; +}; diff --git a/tests/baselines/reference/emitMethodCalledNew.symbols b/tests/baselines/reference/emitMethodCalledNew.symbols new file mode 100644 index 0000000000000..834678bff4fd5 --- /dev/null +++ b/tests/baselines/reference/emitMethodCalledNew.symbols @@ -0,0 +1,31 @@ +//// [tests/cases/compiler/emitMethodCalledNew.ts] //// + +=== emitMethodCalledNew.ts === +// https://github.com/microsoft/TypeScript/issues/55075 + +export const a = { +>a : Symbol(a, Decl(emitMethodCalledNew.ts, 2, 12)) + + new(x: number) { return x + 1 } +>new : Symbol(new, Decl(emitMethodCalledNew.ts, 2, 18)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 3, 6)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 3, 6)) +} +export const b = { +>b : Symbol(b, Decl(emitMethodCalledNew.ts, 5, 12)) + + "new"(x: number) { return x + 1 } +>"new" : Symbol("new", Decl(emitMethodCalledNew.ts, 5, 18)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 6, 8)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 6, 8)) +} +export const c = { +>c : Symbol(c, Decl(emitMethodCalledNew.ts, 8, 12)) + + ["new"](x: number) { return x + 1 } +>["new"] : Symbol(["new"], Decl(emitMethodCalledNew.ts, 8, 18)) +>"new" : Symbol(["new"], Decl(emitMethodCalledNew.ts, 8, 18)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 9, 10)) +>x : Symbol(x, Decl(emitMethodCalledNew.ts, 9, 10)) +} + diff --git a/tests/baselines/reference/emitMethodCalledNew.types b/tests/baselines/reference/emitMethodCalledNew.types new file mode 100644 index 0000000000000..de0be00a5120c --- /dev/null +++ b/tests/baselines/reference/emitMethodCalledNew.types @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/emitMethodCalledNew.ts] //// + +=== emitMethodCalledNew.ts === +// https://github.com/microsoft/TypeScript/issues/55075 + +export const a = { +>a : { "new"(x: number): number; } +>{ new(x: number) { return x + 1 }} : { "new"(x: number): number; } + + new(x: number) { return x + 1 } +>new : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 +} +export const b = { +>b : { "new"(x: number): number; } +>{ "new"(x: number) { return x + 1 }} : { "new"(x: number): number; } + + "new"(x: number) { return x + 1 } +>"new" : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 +} +export const c = { +>c : { "new"(x: number): number; } +>{ ["new"](x: number) { return x + 1 }} : { "new"(x: number): number; } + + ["new"](x: number) { return x + 1 } +>["new"] : (x: number) => number +>"new" : "new" +>x : number +>x + 1 : number +>x : number +>1 : 1 +} + diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types index 0dfc19dea0665..34c399156fd78 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignatures2.types @@ -32,8 +32,8 @@ var a: { new(x: Date): string } >x : Date var b = { new(x: RegExp) { return ''; } }; // not a construct signature, function called new ->b : { new(x: RegExp): string; } ->{ new(x: RegExp) { return ''; } } : { new(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } +>{ new(x: RegExp) { return ''; } } : { "new"(x: RegExp): string; } >new : (x: RegExp) => string >x : RegExp >'' : "" @@ -89,17 +89,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: RegExp): string; }): any; } ->x : { new(x: RegExp): string; } ->b : { new(x: RegExp): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: RegExp): string; }): any; } +>x : { "new"(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: RegExp): string; }): any; (x: typeof b): any; } ->x : { new(x: RegExp): string; } ->b : { new(x: RegExp): string; } +>foo4 : { (x: { "new"(x: RegExp): string; }): any; (x: typeof b): any; } +>x : { "new"(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: RegExp): string; }): any; (x: { new(x: RegExp): string; }): any; } +>foo4 : { (x: { "new"(x: RegExp): string; }): any; (x: { "new"(x: RegExp): string; }): any; } >x : any function foo8(x: B); @@ -140,16 +140,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: RegExp): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: RegExp): string; } ->b : { new(x: RegExp): string; } +>x : { "new"(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: RegExp): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: RegExp): string; }): any; } >x : any function foo12(x: I); @@ -190,16 +190,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: RegExp): string; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: RegExp): string; } ->b : { new(x: RegExp): string; } +>x : { "new"(x: RegExp): string; } +>b : { "new"(x: RegExp): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: RegExp): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: RegExp): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types index d77dd7fb06a90..bd1c494205e8c 100644 --- a/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithConstructSignaturesDifferingParamCounts.types @@ -35,8 +35,8 @@ var a: { new(x: string, y: string): string } >y : string var b = { new(x: string) { return ''; } }; // not a construct signature, function called new ->b : { new(x: string): string; } ->{ new(x: string) { return ''; } } : { new(x: string): string; } +>b : { "new"(x: string): string; } +>{ new(x: string) { return ''; } } : { "new"(x: string): string; } >new : (x: string) => string >x : string >'' : "" @@ -92,17 +92,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: string): string; }): any; } ->x : { new(x: string): string; } ->b : { new(x: string): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: string): string; }): any; } +>x : { "new"(x: string): string; } +>b : { "new"(x: string): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: string): string; }): any; (x: typeof b): any; } ->x : { new(x: string): string; } ->b : { new(x: string): string; } +>foo4 : { (x: { "new"(x: string): string; }): any; (x: typeof b): any; } +>x : { "new"(x: string): string; } +>b : { "new"(x: string): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: string): string; }): any; (x: { new(x: string): string; }): any; } +>foo4 : { (x: { "new"(x: string): string; }): any; (x: { "new"(x: string): string; }): any; } >x : any function foo8(x: B); @@ -143,16 +143,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: string): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: string): string; } ->b : { new(x: string): string; } +>x : { "new"(x: string): string; } +>b : { "new"(x: string): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: string): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: string): string; }): any; } >x : any function foo12(x: I); @@ -193,16 +193,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: string): string; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: string): string; } ->b : { new(x: string): string; } +>x : { "new"(x: string): string; } +>b : { "new"(x: string): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: string): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: string): string; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types index 0f0ef8d5d02ee..de2e1e509a695 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints.types @@ -34,8 +34,8 @@ var a: { new>(x: T): string } >x : T var b = { new(x: T) { return ''; } }; // not a construct signature, function called new ->b : { new(x: T): string; } ->{ new(x: T) { return ''; } } : { new(x: T): string; } +>b : { "new"(x: T): string; } +>{ new(x: T) { return ''; } } : { "new"(x: T): string; } >new : (x: T) => string >x : T >'' : "" @@ -91,17 +91,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T): string; }): any; } ->x : { new(x: T): string; } ->b : { new(x: T): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T): string; }): any; } +>x : { "new"(x: T): string; } +>b : { "new"(x: T): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T): string; }): any; (x: typeof b): any; } ->x : { new(x: T): string; } ->b : { new(x: T): string; } +>foo4 : { (x: { "new"(x: T): string; }): any; (x: typeof b): any; } +>x : { "new"(x: T): string; } +>b : { "new"(x: T): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T): string; }): any; (x: { new(x: T): string; }): any; } +>foo4 : { (x: { "new"(x: T): string; }): any; (x: { "new"(x: T): string; }): any; } >x : any function foo8(x: B>); @@ -142,16 +142,16 @@ function foo10(x: any) { } >x : any function foo11(x: B>); ->foo11 : { (x: B>): any; (x: { new(x: T): string; }): any; } +>foo11 : { (x: B>): any; (x: { "new"(x: T): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T): string; } ->b : { new(x: T): string; } +>x : { "new"(x: T): string; } +>b : { "new"(x: T): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): string; }): any; } >x : any function foo12(x: I); @@ -192,15 +192,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): string; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T): string; } ->b : { new(x: T): string; } +>x : { "new"(x: T): string; } +>b : { "new"(x: T): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): string; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints2.types index 32ccfc172bf7e..f356abc56a9f7 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints2.types @@ -47,8 +47,8 @@ var a: { new>(x: T, y: U): string } >y : U var b = { new(x: T, y: U) { return ''; } }; // not a construct signature, function called new ->b : { new(x: T, y: U): string; } ->{ new(x: T, y: U) { return ''; } } : { new(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } +>{ new(x: T, y: U) { return ''; } } : { "new"(x: T, y: U): string; } >new : (x: T, y: U) => string >x : T >y : U @@ -105,17 +105,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y: U): string; }): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y: U): string; }): any; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y: U): string; }): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>foo4 : { (x: { "new"(x: T, y: U): string; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y: U): string; }): any; (x: { new(x: T, y: U): string; }): any; } +>foo4 : { (x: { "new"(x: T, y: U): string; }): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any function foo5c(x: C); @@ -180,16 +180,16 @@ function foo10(x: any) { } >x : any function foo11(x: B, Array>); ->foo11 : { (x: B, Array>): any; (x: { new(x: T, y: U): string; }): any; } +>foo11 : { (x: B, Array>): any; (x: { "new"(x: T, y: U): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y: U): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any function foo12(x: I); @@ -230,15 +230,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T, y: U): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y: U): string; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T, y: U): string; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints3.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints3.types index bf97ae6b02c1b..02e645c133426 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByConstraints3.types @@ -67,8 +67,8 @@ var a: { new(x: T, y: U): string } >y : U var b = { new(x: T, y: U) { return ''; } }; // not a construct signature, function called new ->b : { new(x: T, y: U): string; } ->{ new(x: T, y: U) { return ''; } } : { new(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } +>{ new(x: T, y: U) { return ''; } } : { "new"(x: T, y: U): string; } >new : (x: T, y: U) => string >x : T >y : U @@ -125,17 +125,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y: U): string; }): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y: U): string; }): any; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y: U): string; }): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>foo4 : { (x: { "new"(x: T, y: U): string; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y: U): string; }): any; (x: { new(x: T, y: U): string; }): any; } +>foo4 : { (x: { "new"(x: T, y: U): string; }): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any function foo5c(x: C); @@ -200,16 +200,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T, y: U): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): string; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y: U): string; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any function foo12(x: I, Five>); @@ -250,15 +250,15 @@ function foo13(x: any) { } >x : any function foo14(x: I, Five>); ->foo14 : { (x: I, Five>): any; (x: { new(x: T, y: U): string; }): any; } +>foo14 : { (x: I, Five>): any; (x: { "new"(x: T, y: U): string; }): any; } >x : I, Five> function foo14(x: typeof b); // ok >foo14 : { (x: I, Five>): any; (x: typeof b): any; } ->x : { new(x: T, y: U): string; } ->b : { new(x: T, y: U): string; } +>x : { "new"(x: T, y: U): string; } +>b : { "new"(x: T, y: U): string; } function foo14(x: any) { } ->foo14 : { (x: I, Five>): any; (x: { new(x: T, y: U): string; }): any; } +>foo14 : { (x: I, Five>): any; (x: { "new"(x: T, y: U): string; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types index 6c35b07b35179..6fae02bf0cd03 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.types @@ -34,8 +34,8 @@ var a: { new(x: T): T } >x : T var b = { new(x: T): T { return null; } }; // not a construct signature, function called new ->b : { new(x: T): T; } ->{ new(x: T): T { return null; } } : { new(x: T): T; } +>b : { "new"(x: T): T; } +>{ new(x: T): T { return null; } } : { "new"(x: T): T; } >new : (x: T) => T >x : T @@ -90,31 +90,31 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T): T; }): any; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T): T; }): any; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T): T; }): any; (x: typeof b): any; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>foo4 : { (x: { "new"(x: T): T; }): any; (x: typeof b): any; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T): T; }): any; (x: { new(x: T): T; }): any; } +>foo4 : { (x: { "new"(x: T): T; }): any; (x: { "new"(x: T): T; }): any; } >x : any function foo5(x: typeof a): number; ->foo5 : { (x: typeof a): number; (x: { new(x: T): T; }): string; } +>foo5 : { (x: typeof a): number; (x: { "new"(x: T): T; }): string; } >x : new (x: T) => T >a : new (x: T) => T function foo5(x: typeof b): string; // ok >foo5 : { (x: new (x: T) => T): number; (x: typeof b): string; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo5(x: any): any { } ->foo5 : { (x: new (x: T) => T): number; (x: { new(x: T): T; }): string; } +>foo5 : { (x: new (x: T) => T): number; (x: { "new"(x: T): T; }): string; } >x : any function foo8(x: B); @@ -155,16 +155,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): T; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T): T; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): T; }): any; } >x : any function foo12(x: I); @@ -205,16 +205,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): T; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T): T; } ->b : { new(x: T): T; } +>x : { "new"(x: T): T; } +>b : { "new"(x: T): T; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T): T; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): T; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types index 1d95296be6e2c..09002456b70ee 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType2.types @@ -34,8 +34,8 @@ var a: { new(x: T): T } >x : T var b = { new(x: T) { return null; } }; // not a construct signature, function called new ->b : { new(x: T): any; } ->{ new(x: T) { return null; } } : { new(x: T): any; } +>b : { "new"(x: T): any; } +>{ new(x: T) { return null; } } : { "new"(x: T): any; } >new : (x: T) => any >x : T @@ -90,17 +90,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T): any; }): any; } ->x : { new(x: T): any; } ->b : { new(x: T): any; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T): any; }): any; } +>x : { "new"(x: T): any; } +>b : { "new"(x: T): any; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T): any; }): any; (x: typeof b): any; } ->x : { new(x: T): any; } ->b : { new(x: T): any; } +>foo4 : { (x: { "new"(x: T): any; }): any; (x: typeof b): any; } +>x : { "new"(x: T): any; } +>b : { "new"(x: T): any; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T): any; }): any; (x: { new(x: T): any; }): any; } +>foo4 : { (x: { "new"(x: T): any; }): any; (x: { "new"(x: T): any; }): any; } >x : any function foo8(x: B); @@ -141,16 +141,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): any; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T): any; } ->b : { new(x: T): any; } +>x : { "new"(x: T): any; } +>b : { "new"(x: T): any; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T): any; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T): any; }): any; } >x : any function foo12(x: I); @@ -191,16 +191,16 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): any; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T): any; } ->b : { new(x: T): any; } +>x : { "new"(x: T): any; } +>b : { "new"(x: T): any; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T): any; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T): any; }): any; } >x : any function foo15(x: I2); diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types index a498c166bc9bf..477e469cc1482 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterCounts.types @@ -32,8 +32,8 @@ var a: { new (x: Z): C; } >x : Z var b = { new(x: A) { return x; } }; ->b : { new(x: A): A; } ->{ new(x: A) { return x; } } : { new(x: A): A; } +>b : { "new"(x: A): A; } +>{ new(x: A) { return x; } } : { "new"(x: A): A; } >new : (x: A) => A >x : A >x : A @@ -89,17 +89,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: A): A; }): any; } ->x : { new(x: A): A; } ->b : { new(x: A): A; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: A): A; }): any; } +>x : { "new"(x: A): A; } +>b : { "new"(x: A): A; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: A): A; }): any; (x: typeof b): any; } ->x : { new(x: A): A; } ->b : { new(x: A): A; } +>foo4 : { (x: { "new"(x: A): A; }): any; (x: typeof b): any; } +>x : { "new"(x: A): A; } +>b : { "new"(x: A): A; } function foo4(x: any) { } ->foo4 : { (x: { new(x: A): A; }): any; (x: { new(x: A): A; }): any; } +>foo4 : { (x: { "new"(x: A): A; }): any; (x: { "new"(x: A): A; }): any; } >x : any function foo8(x: B); @@ -140,16 +140,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: A): A; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: A): A; } ->b : { new(x: A): A; } +>x : { "new"(x: A): A; } +>b : { "new"(x: A): A; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: A): A; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: A): A; }): any; } >x : any function foo12(x: I, number, Date, string>); @@ -190,15 +190,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: A): A; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: A): A; } ->b : { new(x: A): A; } +>x : { "new"(x: A): A; } +>b : { "new"(x: A): A; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: A): A; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: A): A; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types index 9e5e401ce5ac3..64b2d8ca3795f 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesDifferingTypeParameterNames.types @@ -32,8 +32,8 @@ var a: { new(x: Z): B } >x : Z var b = { new(x: A) { return new C(x); } }; ->b : { new(x: A): C; } ->{ new(x: A) { return new C(x); } } : { new(x: A): C; } +>b : { "new"(x: A): C; } +>{ new(x: A) { return new C(x); } } : { "new"(x: A): C; } >new : (x: A) => C >x : A >new C(x) : C @@ -91,17 +91,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: A): C; }): any; } ->x : { new(x: A): C; } ->b : { new(x: A): C; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: A): C; }): any; } +>x : { "new"(x: A): C; } +>b : { "new"(x: A): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: A): C; }): any; (x: typeof b): any; } ->x : { new(x: A): C; } ->b : { new(x: A): C; } +>foo4 : { (x: { "new"(x: A): C; }): any; (x: typeof b): any; } +>x : { "new"(x: A): C; } +>b : { "new"(x: A): C; } function foo4(x: any) { } ->foo4 : { (x: { new(x: A): C; }): any; (x: { new(x: A): C; }): any; } +>foo4 : { (x: { "new"(x: A): C; }): any; (x: { "new"(x: A): C; }): any; } >x : any function foo8(x: B); @@ -142,16 +142,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: A): C; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: A): C; } ->b : { new(x: A): C; } +>x : { "new"(x: A): C; } +>b : { "new"(x: A): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: A): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: A): C; }): any; } >x : any function foo12(x: I); @@ -192,15 +192,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: A): C; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: A): C; } ->b : { new(x: A): C; } +>x : { "new"(x: A): C; } +>b : { "new"(x: A): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: A): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: A): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types index 2fc3493fae3b1..f07a9f58d6e9f 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams.types @@ -39,8 +39,8 @@ var a: { new(x: T, y?: T): B } >y : T var b = { new(x: T, y?: T) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new(x: T, y?: T): C; } ->{ new(x: T, y?: T) { return new C(x, y); } } : { new(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } +>{ new(x: T, y?: T) { return new C(x, y); } } : { "new"(x: T, y?: T): C; } >new : (x: T, y?: T) => C >x : T >y : T @@ -100,17 +100,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y?: T): C; }): any; } ->x : { new(x: T, y?: T): C; } ->b : { new(x: T, y?: T): C; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y?: T): C; }): any; } +>x : { "new"(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: typeof b): any; } ->x : { new(x: T, y?: T): C; } ->b : { new(x: T, y?: T): C; } +>foo4 : { (x: { "new"(x: T, y?: T): C; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y?: T): C; }): any; (x: { new(x: T, y?: T): C; }): any; } +>foo4 : { (x: { "new"(x: T, y?: T): C; }): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : any function foo8(x: B): string; @@ -151,16 +151,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y?: T): C; } ->b : { new(x: T, y?: T): C; } +>x : { "new"(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y?: T): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : any function foo12(x: I); @@ -201,15 +201,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T, y?: T): C; } ->b : { new(x: T, y?: T): C; } +>x : { "new"(x: T, y?: T): C; } +>b : { "new"(x: T, y?: T): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T, y?: T): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y?: T): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types index f629ad0673838..79967629250e4 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams2.types @@ -39,8 +39,8 @@ var a: { new(x: T, y?: U): B } >y : U var b = { new(x: T, y?: U) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new(x: T, y?: U): C; } ->{ new(x: T, y?: U) { return new C(x, y); } } : { new(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } +>{ new(x: T, y?: U) { return new C(x, y); } } : { "new"(x: T, y?: U): C; } >new : (x: T, y?: U) => C >x : T >y : U @@ -100,17 +100,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y?: U): C; }): any; } ->x : { new(x: T, y?: U): C; } ->b : { new(x: T, y?: U): C; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y?: U): C; }): any; } +>x : { "new"(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: typeof b): any; } ->x : { new(x: T, y?: U): C; } ->b : { new(x: T, y?: U): C; } +>foo4 : { (x: { "new"(x: T, y?: U): C; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y?: U): C; }): any; (x: { new(x: T, y?: U): C; }): any; } +>foo4 : { (x: { "new"(x: T, y?: U): C; }): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : any function foo8(x: B); @@ -151,16 +151,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y?: U): C; } ->b : { new(x: T, y?: U): C; } +>x : { "new"(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y?: U): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : any function foo12(x: I); @@ -201,15 +201,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T, y?: U): C; } ->b : { new(x: T, y?: U): C; } +>x : { "new"(x: T, y?: U): C; } +>b : { "new"(x: T, y?: U): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T, y?: U): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y?: U): C; }): any; } >x : any diff --git a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types index 5917ef0e0ae11..9d1c287e6e356 100644 --- a/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types +++ b/tests/baselines/reference/objectTypesIdentityWithGenericConstructSignaturesOptionalParams3.types @@ -39,8 +39,8 @@ var a: { new (x: T, y?: U): B }; >y : U var b = { new(x: T, y: U) { return new C(x, y); } }; // not a construct signature, function called new ->b : { new(x: T, y: U): C; } ->{ new(x: T, y: U) { return new C(x, y); } } : { new(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } +>{ new(x: T, y: U) { return new C(x, y); } } : { "new"(x: T, y: U): C; } >new : (x: T, y: U) => C >x : T >y : U @@ -100,17 +100,17 @@ function foo3(x: any) { } >x : any function foo4(x: typeof b); ->foo4 : { (x: typeof b): any; (x: { new(x: T, y: U): C; }): any; } ->x : { new(x: T, y: U): C; } ->b : { new(x: T, y: U): C; } +>foo4 : { (x: typeof b): any; (x: { "new"(x: T, y: U): C; }): any; } +>x : { "new"(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } function foo4(x: typeof b); // error ->foo4 : { (x: { new(x: T, y: U): C; }): any; (x: typeof b): any; } ->x : { new(x: T, y: U): C; } ->b : { new(x: T, y: U): C; } +>foo4 : { (x: { "new"(x: T, y: U): C; }): any; (x: typeof b): any; } +>x : { "new"(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } function foo4(x: any) { } ->foo4 : { (x: { new(x: T, y: U): C; }): any; (x: { new(x: T, y: U): C; }): any; } +>foo4 : { (x: { "new"(x: T, y: U): C; }): any; (x: { "new"(x: T, y: U): C; }): any; } >x : any function foo8(x: B); @@ -151,16 +151,16 @@ function foo10(x: any) { } >x : any function foo11(x: B); ->foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): C; }): any; } >x : B function foo11(x: typeof b); // ok >foo11 : { (x: B): any; (x: typeof b): any; } ->x : { new(x: T, y: U): C; } ->b : { new(x: T, y: U): C; } +>x : { "new"(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } function foo11(x: any) { } ->foo11 : { (x: B): any; (x: { new(x: T, y: U): C; }): any; } +>foo11 : { (x: B): any; (x: { "new"(x: T, y: U): C; }): any; } >x : any function foo12(x: I); @@ -201,15 +201,15 @@ function foo13(x: any) { } >x : any function foo14(x: I); ->foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y: U): C; }): any; } >x : I function foo14(x: typeof b); // ok >foo14 : { (x: I): any; (x: typeof b): any; } ->x : { new(x: T, y: U): C; } ->b : { new(x: T, y: U): C; } +>x : { "new"(x: T, y: U): C; } +>b : { "new"(x: T, y: U): C; } function foo14(x: any) { } ->foo14 : { (x: I): any; (x: { new(x: T, y: U): C; }): any; } +>foo14 : { (x: I): any; (x: { "new"(x: T, y: U): C; }): any; } >x : any diff --git a/tests/baselines/reference/parser645484.types b/tests/baselines/reference/parser645484.types index 290fb19fcc9f8..7dcf7f95eca7b 100644 --- a/tests/baselines/reference/parser645484.types +++ b/tests/baselines/reference/parser645484.types @@ -2,7 +2,7 @@ === parser645484.ts === var c : { ->c : { new?(): any; } +>c : { "new"?(): any; } new?(): any; >new : () => any diff --git a/tests/baselines/reference/vardecl.types b/tests/baselines/reference/vardecl.types index 39ed0dbee7492..1703a6fed1d9a 100644 --- a/tests/baselines/reference/vardecl.types +++ b/tests/baselines/reference/vardecl.types @@ -66,7 +66,7 @@ var n1: { [s: string]: number; }; >s : string var c : { ->c : { new?(): any; } +>c : { "new"?(): any; } new? (): any; >new : () => any diff --git a/tests/cases/compiler/emitMethodCalledNew.ts b/tests/cases/compiler/emitMethodCalledNew.ts new file mode 100644 index 0000000000000..0bc59c9a54e50 --- /dev/null +++ b/tests/cases/compiler/emitMethodCalledNew.ts @@ -0,0 +1,13 @@ +// @declaration: true + +// https://github.com/microsoft/TypeScript/issues/55075 + +export const a = { + new(x: number) { return x + 1 } +} +export const b = { + "new"(x: number) { return x + 1 } +} +export const c = { + ["new"](x: number) { return x + 1 } +} diff --git a/tests/cases/fourslash/codeFixAddMissingMember31.ts b/tests/cases/fourslash/codeFixAddMissingMember31.ts new file mode 100644 index 0000000000000..62f488b3ac3a2 --- /dev/null +++ b/tests/cases/fourslash/codeFixAddMissingMember31.ts @@ -0,0 +1,17 @@ +/// + +////class C { +//// "new"(x: number) {} +////} +////[|const foo: C = {}|]; + +verify.codeFix({ + index: 0, + description: ts.Diagnostics.Add_missing_properties.message, + newRangeContent: +`const foo: C = { + new: function(x: number): void { + throw new Error("Function not implemented."); + } +}` +});