Title: Type guards don't work for interfaces with only optional properties · Issue #5842 · microsoft/TypeScript · GitHub
Open Graph Title: Type guards don't work for interfaces with only optional properties · Issue #5842 · microsoft/TypeScript
X Title: Type guards don't work for interfaces with only optional properties · Issue #5842 · microsoft/TypeScript
Description: For some reason type guards to not work if an interface has only optional properties. interface A { foo : number; } function isA(object: any): object is A { return true; } let a: A | boolean; if (isA(a)) { a.foo; // compiles } interface ...
Open Graph Description: For some reason type guards to not work if an interface has only optional properties. interface A { foo : number; } function isA(object: any): object is A { return true; } let a: A | boolean; if (i...
X Description: For some reason type guards to not work if an interface has only optional properties. interface A { foo : number; } function isA(object: any): object is A { return true; } let a: A | boolean; if (i...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5842
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type guards don't work for interfaces with only optional properties","articleBody":"For some reason type guards to not work if an interface has only optional properties. \n\n``` ts\ninterface A {\n foo : number;\n}\n\nfunction isA(object: any): object is A {\n return true;\n}\n\nlet a: A | boolean;\n\nif (isA(a)) {\n a.foo; // compiles\n}\n\n\n\ninterface B {\n foo? : number;\n}\n\nfunction isB(object: any): object is B {\n return true;\n}\n\nlet b: B | boolean;\n\nif (isB(b)) {\n b.foo; // does not compile because type inference says its `B | boolean`\n}\n```\n","author":{"url":"https://github.com/domoritz","@type":"Person","name":"domoritz"},"datePublished":"2015-11-30T22:19:44Z","url":"https://github.com/microsoft/TypeScript/issues/5842"}
| 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:719629cd-9090-5f62-942d-1e9357f35fa1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A978:272DC0:221ACB:2C7015:6B00CC23 |
| html-safe-nonce | 7453ae1329a71f6846776e5cfe06e6b084cd871ca99346adad487ca13f08bb75 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTc4OjI3MkRDMDoyMjFBQ0I6MkM3MDE1OjZCMDBDQzIzIiwidmlzaXRvcl9pZCI6Ijc0ODEzOTc3NTM2NzE2MzM5NTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 5fdf9e3aa50114e0a9a846fcb6c47b288bec083871532b1512e3ff4acf61b2b0 |
| hovercard-subject-tag | issue:119594138 |
| 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/5842/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53f3950c0f886b2b3be353876e0092b162a01a706250a8f52b1c457737cbd48c/microsoft/TypeScript/issues/5842 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53f3950c0f886b2b3be353876e0092b162a01a706250a8f52b1c457737cbd48c/microsoft/TypeScript/issues/5842 |
| og:image:alt | For some reason type guards to not work if an interface has only optional properties. interface A { foo : number; } function isA(object: any): object is A { return true; } let a: A | boolean; if (i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | domoritz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| 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 | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width