Title: In JSDoc, `?` of conditional is frequently parsed as postfix-`?` · Issue #27424 · microsoft/TypeScript · GitHub
Open Graph Title: In JSDoc, `?` of conditional is frequently parsed as postfix-`?` · Issue #27424 · microsoft/TypeScript
X Title: In JSDoc, `?` of conditional is frequently parsed as postfix-`?` · Issue #27424 · microsoft/TypeScript
Description: TypeScript Version: 3.2.0-dev.20180927 Search Terms: JSDoc conditional types Using Conditional Types in JSDoc comments confuses the TypeScript parser since the T extends Y ? A : B syntax looks similar to the Y? (meaning Y|null) syntax fr...
Open Graph Description: TypeScript Version: 3.2.0-dev.20180927 Search Terms: JSDoc conditional types Using Conditional Types in JSDoc comments confuses the TypeScript parser since the T extends Y ? A : B syntax looks simi...
X Description: TypeScript Version: 3.2.0-dev.20180927 Search Terms: JSDoc conditional types Using Conditional Types in JSDoc comments confuses the TypeScript parser since the T extends Y ? A : B syntax looks simi...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/27424
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"In JSDoc, `?` of conditional is frequently parsed as postfix-`?`","articleBody":"**TypeScript Version:** 3.2.0-dev.20180927\r\n**Search Terms:** JSDoc conditional types\r\n\r\nUsing [Conditional Types](https://www.typescriptlang.org/docs/handbook/advanced-types.html#conditional-types) in JSDoc comments confuses the TypeScript parser since the `T extends Y ? A : B` syntax looks similar to the `Y?` (meaning `Y|null`) syntax from JSDoc.\r\n\r\n**Code**\r\n\r\n```js\r\n/**\r\n * @template {{}} T\r\n * @param {T} o\r\n * @returns {T extends Readonly\u003cinfer U> ? (keyof U)[] : string[]}\r\n */\r\nfunction Object_keys(o) {\r\n\tlet keys = Object.keys(o);\r\n\t// @ts-ignore: Type assertion for stripping `Readonly\u003c…>`\r\n\treturn keys;\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nNo error should be reported.\r\nThe type of `Object_keys` should be: `\u003cT extends {}>(o: T): T extends Readonly\u003cinfer U> ? (keyof U)[] : string[]`.\r\n\r\n**Actual behavior:**\r\n\r\nTypeScript compiler shows an error (*\"?\" expected*) and mistakes the existing `?` operator for JSDoc `\u003ctype>|null` syntax.\r\n\r\nThe actual type therefor ends up being: `\u003cT extends {}>(o: T): T extends Readonly\u003cinfer U> | null ? (keyof U)[] : string[]`.\r\n\r\n**Possible fixes:**\r\n\r\n 1. When encountering a top-level (not within parenthesis) `?` token in an extends clause, scan ahead and check whether it is followed by an `|` or `&` token (type intersection or union operators). If yes, treat it as `|null` and keep processing; otherwise, assume it's the start of a conditional type declaration. (Requires at least an LF(2) parser.)\r\n 2. Prohibit the JSDoc `?` operator in the top-level of an extends clause, always causing it to be treated as the start of the conditional type declaration.\r\n\r\n**Playground Link:** None, Playground does not seem to support JavaScript with JSDoc instead of TypeScript as input.","author":{"url":"https://github.com/ntninja","@type":"Person","name":"ntninja"},"datePublished":"2018-09-28T11:24:57Z","url":"https://github.com/microsoft/TypeScript/issues/27424"}
| 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:b709c152-f883-875d-543d-8fe2d3d06169 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AF46:14ECB:A16FBD:CEDB9E:6B00F23E |
| html-safe-nonce | 8c24d33a232a772f4155d68671997cb06e7f2648b4ce832d5b82df1aa3f4f99e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjQ2OjE0RUNCOkExNkZCRDpDRURCOUU6NkIwMEYyM0UiLCJ2aXNpdG9yX2lkIjoiMTg3NjE1ODcxNzUyNTY2MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5f1d727d790db02ee8527fcdc6106e319b25b5da0941d90277c47385fde23eac |
| hovercard-subject-tag | issue:364849439 |
| 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/27424/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6e74e8a0fb0d232ec126dbba7605854ae8d3b9d66772226122721ced69464d71/microsoft/TypeScript/issues/27424 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6e74e8a0fb0d232ec126dbba7605854ae8d3b9d66772226122721ced69464d71/microsoft/TypeScript/issues/27424 |
| og:image:alt | TypeScript Version: 3.2.0-dev.20180927 Search Terms: JSDoc conditional types Using Conditional Types in JSDoc comments confuses the TypeScript parser since the T extends Y ? A : B syntax looks simi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ntninja |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width