Title: add type-guard for `void` · Issue #1806 · microsoft/TypeScript · GitHub
Open Graph Title: add type-guard for `void` · Issue #1806 · microsoft/TypeScript
X Title: add type-guard for `void` · Issue #1806 · microsoft/TypeScript
Description: There is a type that is quite interesting in typescript void | {}, this type has some unique behavior, everything can be assigned to this type, but the compiler does not infer any property for this type unlike for {} that inherits the ba...
Open Graph Description: There is a type that is quite interesting in typescript void | {}, this type has some unique behavior, everything can be assigned to this type, but the compiler does not infer any property for this...
X Description: There is a type that is quite interesting in typescript void | {}, this type has some unique behavior, everything can be assigned to this type, but the compiler does not infer any property for this...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/1806
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"add type-guard for `void`","articleBody":"There is a type that is quite interesting in typescript `void | {}`, this type has some unique behavior, everything can be assigned to this type, but the compiler does not infer any property for this type unlike for `{}` that inherits the basic object properties, the difference with `{}` is subtile but still pretty interesting: \n\n``` typescript\nfunction func1(val: {} ) {\n val.hasOwnProperty('hello'); // no error\n}\nfunction func2(val: {} | void) {\n val.hasOwnProperty('hello'); // error: Property 'hasOwnProperty' does not exist on type 'void | {}'.\n}\n```\n\nHowever there is not typeguard for `void`, it could be interesting to add some type guards for this case: \n- `typeof val !== 'undefined'`\n- `val !== undefined`\n- `val != undefined`\n- `val != null`\n","author":{"url":"https://github.com/fdecampredon","@type":"Person","name":"fdecampredon"},"datePublished":"2015-01-26T11:37:05Z","url":"https://github.com/microsoft/TypeScript/issues/1806"}
| 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:e5d3fa43-6049-9549-3450-104d5d9da7cd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D470:25F127:63F7B9:87E5B8:6B00768F |
| html-safe-nonce | 8c81adad2d6dd0160c959fcced44fe279d1cad1aa067b4072be8562fe1c0ac03 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDcwOjI1RjEyNzo2M0Y3Qjk6ODdFNUI4OjZCMDA3NjhGIiwidmlzaXRvcl9pZCI6IjE3NDcxNjY0NjQxNDc3NDg0OTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | eb525fcfaba4f4aaf0c24bf974ce77ace84bc76a94ca976800f378d1719214e9 |
| hovercard-subject-tag | issue:55472925 |
| 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/1806/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e0b34e74d9eae7e366863de64308a690438509625560cb23675a55df7c0b0956/microsoft/TypeScript/issues/1806 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e0b34e74d9eae7e366863de64308a690438509625560cb23675a55df7c0b0956/microsoft/TypeScript/issues/1806 |
| og:image:alt | There is a type that is quite interesting in typescript void | {}, this type has some unique behavior, everything can be assigned to this type, but the compiler does not infer any property for this... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fdecampredon |
| hostname | github.com |
| expected-hostname | github.com |
| None | 75c2b65dd205f26961d0c29afed1a8d0bb7cca9f05780571dfd1ef93eb539d16 |
| 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 | 84e563eb4b55f8fa102f325f117533cee9e3df4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width