Title: Type with negative properties cause crash in infer return type · Issue #56562 · microsoft/TypeScript · GitHub
Open Graph Title: Type with negative properties cause crash in infer return type · Issue #56562 · microsoft/TypeScript
X Title: Type with negative properties cause crash in infer return type · Issue #56562 · microsoft/TypeScript
Description: 🔎 Search Terms negative numeric literals infer return type 🕗 Version & Regression Information This is a crash ⏯ Playground Link Playground Link 💻 Code function x() { return { [-1]: 0 } as const } 🙁 Actual behavior When using the refactor...
Open Graph Description: 🔎 Search Terms negative numeric literals infer return type 🕗 Version & Regression Information This is a crash ⏯ Playground Link Playground Link 💻 Code function x() { return { [-1]: 0 } as const } 🙁...
X Description: 🔎 Search Terms negative numeric literals infer return type 🕗 Version & Regression Information This is a crash ⏯ Playground Link Playground Link 💻 Code function x() { return { [-1]: 0 } as const...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/56562
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type with negative properties cause crash in infer return type","articleBody":"### 🔎 Search Terms\r\n\r\nnegative numeric literals infer return type\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is a crash\r\n\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground Link](https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABADwBQEpEG8CwAoRQxAJwFMoRilcCi6BtAWgEYBdALkQAZ86BfRAEMAzoggJhUfHyA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nfunction x() {\r\n return {\r\n [-1]: 0\r\n } as const\r\n}\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nWhen using the refactor `Infer function return type` nothing happens. Extension host in VS Code shows a stack trace ending with:\r\n\r\n```sh\r\nError: Debug Failure. False expression: Token end is child end\r\n at processChildNode (c:\\dev\\TSC\\tmp\\defaults-and-bindings-code-fix\\node_modules\\typescript\\lib\\tsserver.js:171847:17)\r\n at c:\\dev\\TSC\\tmp\\defaults-and-bindings-code-fix\\node_modules\\typescript\\lib\\tsserver.js:171778:9\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\nShould infer `{ readonly [-1]: 0 }` \r\n\r\n### Additional information about the issue\r\n\r\nFound while working on isolated declarations.\r\n\r\nThe 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))`\r\n\r\nThe error occurs in this assertion:\r\n\r\n```ts\r\n if (isToken(child)) {\r\n // if child node is a token, it does not impact indentation, proceed it using parent indentation scope rules\r\n const tokenInfo = formattingScanner.readTokenInfo(child);\r\n // JSX text shouldn't affect indenting\r\n if (child.kind !== SyntaxKind.JsxText) {\r\n Debug.assert(tokenInfo.token.end === child.end, \"Token end is child end\");\r\n consumeTokenAndAdvanceScanner(tokenInfo, node, parentDynamicIndentation, child);\r\n return inheritedIndentation;\r\n }\r\n }\r\n\r\n```\r\n ","author":{"url":"https://github.com/dragomirtitian","@type":"Person","name":"dragomirtitian"},"datePublished":"2023-11-27T18:24:55Z","url":"https://github.com/microsoft/TypeScript/issues/56562"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:458e021b-71ce-b983-4580-18d899f6b237 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95B0:213839:20400F6:2935B4A:6B016031 |
| html-safe-nonce | 4c9b736df553f2da4650b69d3a14d43c6bfcc061feabdcc859696d2a9e832ee7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUIwOjIxMzgzOToyMDQwMEY2OjI5MzVCNEE6NkIwMTYwMzEiLCJ2aXNpdG9yX2lkIjoiMzY3OTI3OTY5NDM0OTQyNjczNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e12ba90c1fbf4c9190f04a0348229054797ecfabac42c54a50e25f8f7ebfd81b |
| hovercard-subject-tag | issue:2012849685 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/56562/issue_layout |
| twitter:image | https://opengraph.githubassets.com/acaf506b74dc51dbcc9593f2b01a7ac68d6b5361f65e9e8fe635613e216ab094/microsoft/TypeScript/issues/56562 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/acaf506b74dc51dbcc9593f2b01a7ac68d6b5361f65e9e8fe635613e216ab094/microsoft/TypeScript/issues/56562 |
| og:image:alt | 🔎 Search Terms negative numeric literals infer return type 🕗 Version & Regression Information This is a crash ⏯ Playground Link Playground Link 💻 Code function x() { return { [-1]: 0 } as const } 🙁... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dragomirtitian |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width