Title: 'for..in' for null/undefined expression should not be an error in --strictNullChecks · Issue #19461 · microsoft/TypeScript · GitHub
Open Graph Title: 'for..in' for null/undefined expression should not be an error in --strictNullChecks · Issue #19461 · microsoft/TypeScript
X Title: 'for..in' for null/undefined expression should not be an error in --strictNullChecks · Issue #19461 · microsoft/TypeScript
Description: // @strictNullChecks: true function f(x: { [key: string]: number; } | null | undefined) { for (const key in x) { // 1 console.log(x[key]); // 2 } } Expected behavior: The for..in statement in ECMAScript does not throw if the expression i...
Open Graph Description: // @strictNullChecks: true function f(x: { [key: string]: number; } | null | undefined) { for (const key in x) { // 1 console.log(x[key]); // 2 } } Expected behavior: The for..in statement in ECMAS...
X Description: // @strictNullChecks: true function f(x: { [key: string]: number; } | null | undefined) { for (const key in x) { // 1 console.log(x[key]); // 2 } } Expected behavior: The for..in statement in ECMAS...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/19461
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"'for..in' for null/undefined expression should not be an error in --strictNullChecks","articleBody":"```ts\r\n// @strictNullChecks: true\r\nfunction f(x: { [key: string]: number; } | null | undefined) {\r\n for (const key in x) { // 1\r\n console.log(x[key]); // 2\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nThe `for..in` statement in ECMAScript does not throw if the expression is `undefined` or `null`, but rather the loop body is not evaluated. As such, the correct behavior under `--strictNullChecks` should be:\r\n\r\n- The `for..in` statement (1) should be legal, even if `x` is `undefined` or `null`.\r\n- Inside the `for..in` statement, the `x` (2) should no longer be considered `undefined` or `null`.\r\n\r\n**Actual behavior:**\r\n\r\n- The `for..in` statement (1) reports the error: `Object is possibly 'null' or 'undefined'.`\r\n- Inside the `for..in` statement, the `x` (2) reports the error: `Object is possibly 'null' or 'undefined'.`","author":{"url":"https://github.com/rbuckton","@type":"Person","name":"rbuckton"},"datePublished":"2017-10-25T00:03:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/19461/TypeScript/issues/19461"}
| 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:bac5e865-b7d8-3670-8d9e-ecf649ba98d5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B79A:2F2710:681924:93985B:6A63065E |
| html-safe-nonce | 43217defd8b9e42bd348ff7e7e0044a61490fe4685bc2aae84c4cd06f32fe5c3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzlBOjJGMjcxMDo2ODE5MjQ6OTM5ODVCOjZBNjMwNjVFIiwidmlzaXRvcl9pZCI6IjYzNTU5Mzk5MTkyMTI1MTI4NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 13369182179fa7db7d2eea924dc8768a007f05956ca503c8de795ef21c59abc3 |
| hovercard-subject-tag | issue:268225613 |
| 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/19461/issue_layout |
| twitter:image | https://opengraph.githubassets.com/03c1733a174999ef4188139b60be00ad4aca563977937fc58b2284aba8ef4e14/microsoft/TypeScript/issues/19461 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/03c1733a174999ef4188139b60be00ad4aca563977937fc58b2284aba8ef4e14/microsoft/TypeScript/issues/19461 |
| og:image:alt | // @strictNullChecks: true function f(x: { [key: string]: number; } | null | undefined) { for (const key in x) { // 1 console.log(x[key]); // 2 } } Expected behavior: The for..in statement in ECMAS... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rbuckton |
| hostname | github.com |
| expected-hostname | github.com |
| None | b48e7bf0b1945d51f303503b057abf666ce74c3efbe107b413db2bb921c3f012 |
| 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 | 9370f37042c29822d6ba7e3f670f0036a0155b21 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width