mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(56562): Type with negative properties cause crash in infer return type (#56565)
This commit is contained in:
@@ -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
|
||||
}`
|
||||
});
|
||||
Reference in New Issue
Block a user