Title: strictNullChecks blocks safe typeof capture · Issue #16108 · microsoft/TypeScript · GitHub
Open Graph Title: strictNullChecks blocks safe typeof capture · Issue #16108 · microsoft/TypeScript
X Title: strictNullChecks blocks safe typeof capture · Issue #16108 · microsoft/TypeScript
Description: Sorry if this is a dupe - I tried searching but github's search isn't great. TypeScript Version: 2.3.1 Code interface Nested { child: { prop: string } } declare function maybeGetNestedValue(): Nested | null const nested = maybeGetNestedV...
Open Graph Description: Sorry if this is a dupe - I tried searching but github's search isn't great. TypeScript Version: 2.3.1 Code interface Nested { child: { prop: string } } declare function maybeGetNestedValue(): Nest...
X Description: Sorry if this is a dupe - I tried searching but github's search isn't great. TypeScript Version: 2.3.1 Code interface Nested { child: { prop: string } } declare function maybeGetNestedValue...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/16108
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"strictNullChecks blocks safe typeof capture","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\nSorry if this is a dupe - I tried searching but github's search isn't great.\r\n\r\n**TypeScript Version:** 2.3.1\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface Nested {\r\n child: {\r\n prop: string\r\n }\r\n}\r\n\r\ndeclare function maybeGetNestedValue(): Nested | null\r\n\r\nconst nested = maybeGetNestedValue()\r\n\r\nconst child: typeof nested.child = {\r\n prop: 'value'\r\n}\r\n```\r\n\r\n[TypeScript Playground link](http://www.typescriptlang.org/play/#src=interface%20Nested%20%7B%0D%0A%20%20%20%20child%3A%20%7B%0D%0A%20%20%20%20%20%20%20%20prop%3A%20string%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Adeclare%20function%20maybeGetNestedValue()%3A%20Nested%20%7C%20null%0D%0A%0D%0Aconst%20nested%20%3D%20maybeGetNestedValue()%0D%0A%0D%0Aconst%20child%3A%20typeof%20nested.child%20%3D%20%7B%0D%0A%20%20%20%20prop%3A%20'value'%0D%0A%7D)\r\n**Note**: You need to manually enable strictNullChecks under the options for this link. If I enable it and try to share it says the text buffer is too big to share.\r\n\r\n\r\n**Expected behavior:** I would expect to be able to use `typeof` to capture the type of this nested field, since as you can see in the emitted code in the TypeScript Playground link, there is no dereference of the `nested` field emitted, so the code should always be safe.\r\n\r\n**Actual behavior:** The strictNullChecks flag raises an error because the `nested` field may be `null`.","author":{"url":"https://github.com/dylanscott","@type":"Person","name":"dylanscott"},"datePublished":"2017-05-26T18:04:02Z","url":"https://github.com/microsoft/TypeScript/issues/16108"}
| 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:f8da4d27-d214-6bb5-6e6b-3c468064dcfa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 979E:81C86:1AFF3E:2568F1:6B0466E1 |
| html-safe-nonce | fec5d68fe93bc182d86b775088592abd26fd3ba769d4ec34e81786404c077d57 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzlFOjgxQzg2OjFBRkYzRToyNTY4RjE6NkIwNDY2RTEiLCJ2aXNpdG9yX2lkIjoiNTMzNTA0MzI4MjYzODc1OTY0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 910034a2476a6f0ba0f2ba3661ae4bb0c4096580c52cf64cb56caad173d9f5d5 |
| hovercard-subject-tag | issue:231696582 |
| 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/16108/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c88c0d43b5698dcf09bfca85c7cf6871145ebe2f854883c47378a68f805627ab/microsoft/TypeScript/issues/16108 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c88c0d43b5698dcf09bfca85c7cf6871145ebe2f854883c47378a68f805627ab/microsoft/TypeScript/issues/16108 |
| og:image:alt | Sorry if this is a dupe - I tried searching but github's search isn't great. TypeScript Version: 2.3.1 Code interface Nested { child: { prop: string } } declare function maybeGetNestedValue(): Nest... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dylanscott |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| 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 | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| 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