Title: strictNullChecks non-null assertion lost inside Array#map callback · Issue #10982 · microsoft/TypeScript · GitHub
Open Graph Title: strictNullChecks non-null assertion lost inside Array#map callback · Issue #10982 · microsoft/TypeScript
X Title: strictNullChecks non-null assertion lost inside Array#map callback · Issue #10982 · microsoft/TypeScript
Description: TypeScript Version: nightly (2.1.0-dev.20160919) Code function f(_: string) {} const foo: {bar: null | string} = {bar: "foo"}; if (foo.bar) { foo.bar.length; // works fine (function () { // works fine foo.bar.length; f(foo.bar); })(); //...
Open Graph Description: TypeScript Version: nightly (2.1.0-dev.20160919) Code function f(_: string) {} const foo: {bar: null | string} = {bar: "foo"}; if (foo.bar) { foo.bar.length; // works fine (function () { // works f...
X Description: TypeScript Version: nightly (2.1.0-dev.20160919) Code function f(_: string) {} const foo: {bar: null | string} = {bar: "foo"}; if (foo.bar) { foo.bar.length; // works fine (function () { ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/10982
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"strictNullChecks non-null assertion lost inside Array#map callback","articleBody":"**TypeScript Version:** nightly (2.1.0-dev.20160919)\n\n**Code**\n\n``` ts\nfunction f(_: string) {}\n\nconst foo: {bar: null | string} = {bar: \"foo\"};\n\nif (foo.bar) {\n foo.bar.length; // works fine\n\n (function () {\n // works fine\n foo.bar.length;\n f(foo.bar);\n })();\n\n // both fail non-null assertion\n [].map(_ => {\n foo.bar.length;\n f(foo.bar);\n });\n}\n```\n\n**Expected behavior:**\n\nThere should be no compile errors, as `foo.bar` is guaranteed to be non-null inside the whole block\n\n**Actual behavior:** \n\nInside the map callback, TS thinks that `foo.bar` can be null. Strangely enough, an IIFE works just fine.\n","author":{"url":"https://github.com/Swatinem","@type":"Person","name":"Swatinem"},"datePublished":"2016-09-19T10:07:49Z","url":"https://github.com/microsoft/TypeScript/issues/10982"}
| 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:3d53bf63-a3ed-c72c-0cf6-83054b2ec498 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D236:134361:C18567:FFFFB7:6B00F273 |
| html-safe-nonce | 0ebcbdc3a97e25b2e928818cbf40e81064163aac14c7463a78142402ef63c904 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjM2OjEzNDM2MTpDMTg1Njc6RkZGRkI3OjZCMDBGMjczIiwidmlzaXRvcl9pZCI6IjY5NTY3NjMyODUxMDIzMjYzODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | bd33f1e2dbfc9053e8046534028030a1ffe17d2d08405011a390006238086941 |
| hovercard-subject-tag | issue:177746949 |
| 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/10982/issue_layout |
| twitter:image | https://opengraph.githubassets.com/78a02e6331bb6afb9b79f37af53378fbb6dfe691f932fd0f491df3a3407b4b9d/microsoft/TypeScript/issues/10982 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/78a02e6331bb6afb9b79f37af53378fbb6dfe691f932fd0f491df3a3407b4b9d/microsoft/TypeScript/issues/10982 |
| og:image:alt | TypeScript Version: nightly (2.1.0-dev.20160919) Code function f(_: string) {} const foo: {bar: null | string} = {bar: "foo"}; if (foo.bar) { foo.bar.length; // works fine (function () { // works f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Swatinem |
| 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