diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 98c79cd187a..27c066e0f57 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8345,7 +8345,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 00000000000..3666033e400 --- /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 +}` +});