Closed
Description
π Search Terms
negative numeric literals infer return type
π Version & Regression Information
- This is a crash
β― Playground Link
π» Code
function x() {
return {
[-1]: 0
} as const
}
π Actual behavior
When using the refactor Infer function return type
nothing happens. Extension host in VS Code shows a stack trace ending with:
Error: Debug Failure. False expression: Token end is child end
at processChildNode (c:\dev\TSC\tmp\defaults-and-bindings-code-fix\node_modules\typescript\lib\tsserver.js:171847:17)
at c:\dev\TSC\tmp\defaults-and-bindings-code-fix\node_modules\typescript\lib\tsserver.js:171778:9
π Expected behavior
Should infer { readonly [-1]: 0 }
Additional information about the issue
Found while working on isolated declarations.
The issue appears to be that the formatter does not deal well with negative numbers in computed properties. This was not a problem before our recent merge with master as the type printer appears to have been producing negative number literals and it now produces the correct UnaryOperator(-, abs(value))
The error occurs in this assertion:
if (isToken(child)) {
// if child node is a token, it does not impact indentation, proceed it using parent indentation scope rules
const tokenInfo = formattingScanner.readTokenInfo(child);
// JSX text shouldn't affect indenting
if (child.kind !== SyntaxKind.JsxText) {
Debug.assert(tokenInfo.token.end === child.end, "Token end is child end");
consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation, child);
return inheritedIndentation;
}
}