Title: bang operator resets type inference · Issue #16945 · microsoft/TypeScript · GitHub
Open Graph Title: bang operator resets type inference · Issue #16945 · microsoft/TypeScript
X Title: bang operator resets type inference · Issue #16945 · microsoft/TypeScript
Description: TypeScript Version: 2.3.4 Code type Foo = { foo:string; }; function isFoo(arg?:any):arg is Foo|undefined{ return true; } function logic(arg?:object){ if (isFoo(arg)){ arg.foo; //Error:(..., 13) TS2532:Object is possibly 'undefined'. arg!...
Open Graph Description: TypeScript Version: 2.3.4 Code type Foo = { foo:string; }; function isFoo(arg?:any):arg is Foo|undefined{ return true; } function logic(arg?:object){ if (isFoo(arg)){ arg.foo; //Error:(..., 13) TS2...
X Description: TypeScript Version: 2.3.4 Code type Foo = { foo:string; }; function isFoo(arg?:any):arg is Foo|undefined{ return true; } function logic(arg?:object){ if (isFoo(arg)){ arg.foo; //Error:(..., 13) TS2...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/16945
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bang operator resets type inference","articleBody":"**TypeScript Version:** 2.3.4\r\n\r\n**Code**\r\n```ts\r\ntype Foo = {\r\n foo:string;\r\n};\r\nfunction isFoo(arg?:any):arg is Foo|undefined{\r\n return true;\r\n}\r\nfunction logic(arg?:object){\r\n if (isFoo(arg)){\r\n arg.foo; //Error:(..., 13) TS2532:Object is possibly 'undefined'. \r\n arg!.foo; //Error:(..., 18) TS2339:Property 'foo' does not exist on type 'object'.\r\n }\r\n}\r\n```\r\n**Expected behavior:**\r\n`arg!` should resolve to foo if it's already inferred that `arg is Foo|undefined`\r\n**Actual behavior:**\r\n`arg!` is resolved to `object`","author":{"url":"https://github.com/amir-arad","@type":"Person","name":"amir-arad"},"datePublished":"2017-07-05T11:16:07Z","url":"https://github.com/microsoft/TypeScript/issues/16945"}
| 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:b5c0bc2e-a933-4398-54aa-2744908bb4e4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B700:2AAD2E:265525A:3331AED:6B01AB12 |
| html-safe-nonce | 5ba824050f28a3ed5531e41638246901aa2abbb2ba51d44c3b789d476f334f9c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzAwOjJBQUQyRToyNjU1MjVBOjMzMzFBRUQ6NkIwMUFCMTIiLCJ2aXNpdG9yX2lkIjoiNDQzNjgwNTk2NDIyNTY4NjI5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 49007bcd39ffff6fdc1c4713b3a271ed0f98f7f87e4384cdb94d6c5407a96c63 |
| hovercard-subject-tag | issue:240618196 |
| 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/16945/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e28ce1e5b7f19fd1565ed2c7e6bdb1c41f699fe1f0a247527c5d89e71c8fec6e/microsoft/TypeScript/issues/16945 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e28ce1e5b7f19fd1565ed2c7e6bdb1c41f699fe1f0a247527c5d89e71c8fec6e/microsoft/TypeScript/issues/16945 |
| og:image:alt | TypeScript Version: 2.3.4 Code type Foo = { foo:string; }; function isFoo(arg?:any):arg is Foo|undefined{ return true; } function logic(arg?:object){ if (isFoo(arg)){ arg.foo; //Error:(..., 13) TS2... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | amir-arad |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width