Title: IteratorResult
Open Graph Title: IteratorResult
X Title: IteratorResult
Description: TypeScript Version: 3.8.3 Search Terms: iterator return type Code const list = ['v1', 'v2', 'v3'] const f: () => Iterator
Open Graph Description: TypeScript Version: 3.8.3 Search Terms: iterator return type Code const list = ['v1', 'v2', 'v3'] const f: () => Iterator
X Description: TypeScript Version: 3.8.3 Search Terms: iterator return type Code const list = ['v1', 'v2', 'v3'] const f: () => Iterator<string> = () => { let index = 0 return ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/38479
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"IteratorResult\u003cT> definition conflicts with the JS spec","articleBody":"**TypeScript Version:** 3.8.3\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms: iterator return type**\r\n\r\n**Code**\r\n\r\n```ts\r\nconst list = ['v1', 'v2', 'v3']\r\n\r\nconst f: () => Iterator\u003cstring> = () => {\r\n let index = 0\r\n return {\r\n next: (): IteratorResult\u003cstring> => {\r\n console.log(list)\r\n if (index \u003c list.length) {\r\n return { value: list[index++]}\r\n } else {\r\n return { done: true }\r\n }\r\n }\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\nThe code should compile without errors.\r\n**Actual behavior:**\r\nThe code compiles with the error: \"Type '{ done: true; }' is not assignable to type 'IteratorResult\u003cstring, any>'.\r\n Property 'value' is missing in type '{ done: true; }' but required in type 'IteratorReturnResult\u003cany>'.(2322)\"\r\n\r\nThe error can be bypassed by changing { done: true } to { value: undefined, done: true }. However, the specification allows omitting the value property. See [Iteration Protocols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)\r\n\r\nA suggested fix would be to change the definition of the type IteratorReturnResult to:\r\n\r\n```ts\r\ninterface IteratorReturnResult\u003cTReturn> {\r\n done: true;\r\n value?: TReturn;\r\n}\r\n```\r\n\r\n**Playground Link:** https://www.typescriptlang.org/play?#code/MYewdgzgLgBANgS2jAvDA2gcgG4EZMA0MOATIcdgMyYC6AUHaJLAGYBcMAFAJSoB8MAJJQApgCcAhlBBiAPNDEIwAcwFoe-GAG86MeCNhKAJiIAeqGAAZdMMQYCuYsNpt6wZqBx4dh4qTIAlEQh7OCh5KEUVNQEdPXiYJggQOBEAOjgQZU5EaG5XeIQWLmMzGFl4JCgMkRUoAAteOIT4uyhHZy0YbAk4exEOXKh0UtMAajGaAF8CvSmYETgIERcW1ocnbRgjcAGYSP6YGbXj+NOZqaA\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n#29982","author":{"url":"https://github.com/ldantonov","@type":"Person","name":"ldantonov"},"datePublished":"2020-05-11T18:16:07Z","url":"https://github.com/microsoft/TypeScript/issues/38479"}
| 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:daf76ef4-cbdc-8d4e-7522-70de6ec435ee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E304:3488ED:100DE85:1682C55:6B044AAA |
| html-safe-nonce | 332239542c3565bc6b198c4b5c362d8e0ffacbef626004025ca339ce7d40503c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzA0OjM0ODhFRDoxMDBERTg1OjE2ODJDNTU6NkIwNDRBQUEiLCJ2aXNpdG9yX2lkIjoiMjAxODc5MTk1OTg2MjQ2MzE0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4311ec51acc594ef58968fa1071a6a3310270697fdc8f9733d2683ca8137fde2 |
| hovercard-subject-tag | issue:616082418 |
| 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/38479/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aff9bdb6f917f8f0d0b7a18445c7282e81b220ff77f8e11a477480b8bbc8258b/microsoft/TypeScript/issues/38479 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aff9bdb6f917f8f0d0b7a18445c7282e81b220ff77f8e11a477480b8bbc8258b/microsoft/TypeScript/issues/38479 |
| og:image:alt | TypeScript Version: 3.8.3 Search Terms: iterator return type Code const list = ['v1', 'v2', 'v3'] const f: () => Iterator |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ldantonov |
| hostname | github.com |
| expected-hostname | github.com |
| None | d4495c3631faba668036f176d1f5946901c5172efd73a6edb984029e7d4f8e46 |
| 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 | 9ac4337fb7c6a5846cdfdb1a04f154d3c33ebc77 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width