Title: Boolean literal types and return type propagation for generators · Issue #2983 · microsoft/TypeScript · GitHub
Open Graph Title: Boolean literal types and return type propagation for generators · Issue #2983 · microsoft/TypeScript
X Title: Boolean literal types and return type propagation for generators · Issue #2983 · microsoft/TypeScript
Description: This suggestion has a few pieces: Implement boolean literal types for true and false, in a fashion similar to #1003 Implement type guards for booleans. Essentially, control flow constructs like if-else, while, for, etc would be subject t...
Open Graph Description: This suggestion has a few pieces: Implement boolean literal types for true and false, in a fashion similar to #1003 Implement type guards for booleans. Essentially, control flow constructs like if-...
X Description: This suggestion has a few pieces: Implement boolean literal types for true and false, in a fashion similar to #1003 Implement type guards for booleans. Essentially, control flow constructs like if-...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/2983
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Boolean literal types and return type propagation for generators","articleBody":"This suggestion has a few pieces:\n1. Implement boolean literal types for `true` and `false`, in a fashion similar to #1003 \n2. Implement type guards for booleans. Essentially, control flow constructs like if-else, while, for, etc would be subject to a type guard if their guard expression is a boolean.\n3. Now we can update generators to have a `next` method that returns `{ done: false; value: TYield; } | { done: true; value: TReturn; }`, where TYield is inferred from the yield expressions of a generator, and TReturn is inferred from the return expressions of a generator.\n4. Iterators would return `{ done: false; value: TYield; } | { done: true; value: any; }` to be compatible with generators.\n5. for-of, spread, array destructuring, and the type yielded by `yield*` would only pick the value associated with done being false.\n6. The value of a `yield*` expression would pick the value associated with done being true.\n7. Introduce a Generator type that can be used to track the desired type of a `yield` expression. This would be TNext, and would be the type of the parameter for the next method on a generator.\n\nThe generator type would look something like this:\n\n``` ts\ninterface Generator\u003cTYield, TReturn, TNext> extends IterableIterator\u003cTYield> {\n next(value?: TNext): IteratorYieldResult\u003cTYield> | IteratorReturnResult\u003cTReturn>;\n throw(exception: any): IteratorYieldResult\u003cTYield> | IteratorReturnResult\u003cTReturn>;\n return(value: any): IteratorYieldResult\u003cTYield> | IteratorReturnResult\u003cTReturn>;\n [Symbol.iterator](): Generator\u003cTYield, TReturn, TNext>;\n [Symbol.toStringTag]: string;\n}\n```\n","author":{"url":"https://github.com/JsonFreeman","@type":"Person","name":"JsonFreeman"},"datePublished":"2015-05-01T01:02:00Z","url":"https://github.com/microsoft/TypeScript/issues/2983"}
| 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:1312e2fe-b81c-b838-feef-1eddaed9d0f6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9732:22EC8D:4E5230:69D22B:6AFBF0B0 |
| html-safe-nonce | c00b0aba17633420fe258e072d4047193f23dd3ec051ca4e0dfb31a17a0f3b2d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzMyOjIyRUM4RDo0RTUyMzA6NjlEMjJCOjZBRkJGMEIwIiwidmlzaXRvcl9pZCI6IjQ2MzIwNTMxODAzNDE2NzgyNTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3a933ba822f37f994d50fbdbcd266667d1b20b173748155d02296159241e1557 |
| hovercard-subject-tag | issue:72323438 |
| 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/2983/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dfaa27e38ccb702472880a2b4d6b2cfc6e56ca2677a0cb1c5daea6f5cf88cee0/microsoft/TypeScript/issues/2983 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dfaa27e38ccb702472880a2b4d6b2cfc6e56ca2677a0cb1c5daea6f5cf88cee0/microsoft/TypeScript/issues/2983 |
| og:image:alt | This suggestion has a few pieces: Implement boolean literal types for true and false, in a fashion similar to #1003 Implement type guards for booleans. Essentially, control flow constructs like if-... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JsonFreeman |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| 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 | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width