diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3a8d1e736f000..261d3e47394f0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8331,7 +8331,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return factory.createStringLiteral(name, !!singleQuote); } if (isNumericLiteralName(name) && startsWith(name, "-")) { - return factory.createComputedPropertyName(factory.createNumericLiteral(+name)); + return factory.createComputedPropertyName(factory.createPrefixUnaryExpression(SyntaxKind.MinusToken, factory.createNumericLiteral(-name))); } return createPropertyNameNodeForIdentifierOrLiteral(name, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed, isMethod); } diff --git a/tests/cases/fourslash/refactorInferFunctionReturnType25.ts b/tests/cases/fourslash/refactorInferFunctionReturnType25.ts new file mode 100644 index 0000000000000..3666033e400bd --- /dev/null +++ b/tests/cases/fourslash/refactorInferFunctionReturnType25.ts @@ -0,0 +1,20 @@ +/// + +////function /*a*//*b*/f() { +//// return { +//// [-1]: 0 +//// } as const +////} + +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Infer function return type", + actionName: "Infer function return type", + actionDescription: "Infer function return type", + newContent: +`function f(): { readonly [-1]: 0; } { + return { + [-1]: 0 + } as const +}` +});