fix(56562): Type with negative properties cause crash in infer return type (#56565)

This commit is contained in:
Oleksandr T
2023-12-07 21:09:53 +02:00
committed by GitHub
parent 5b7344ef52
commit fc30163bb4
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -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);
}
@@ -0,0 +1,20 @@
/// <reference path='fourslash.ts' />
////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
}`
});