Title: [documentation] Clarify the semantics of void · Issue #20006 · microsoft/TypeScript · GitHub
Open Graph Title: [documentation] Clarify the semantics of void · Issue #20006 · microsoft/TypeScript
X Title: [documentation] Clarify the semantics of void · Issue #20006 · microsoft/TypeScript
Description: In the handbook, it's stated that void is a little like the opposite of any: the absence of having any type at all. and Declaring variables of type void is not useful because you can only assign undefined or null to them The latter state...
Open Graph Description: In the handbook, it's stated that void is a little like the opposite of any: the absence of having any type at all. and Declaring variables of type void is not useful because you can only assign un...
X Description: In the handbook, it's stated that void is a little like the opposite of any: the absence of having any type at all. and Declaring variables of type void is not useful because you can only assig...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/20006
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[documentation] Clarify the semantics of void","articleBody":"In [the handbook](https://www.typescriptlang.org/docs/handbook/basic-types.html), it's stated that\r\n\r\n> void is a little like the opposite of any: the absence of having any type at all.\r\n\r\nand\r\n\r\n> Declaring variables of type void is not useful because you can only assign undefined or null to them\r\n\r\nThe latter statement is not true in any useful sense; `null` is not assignable to `void` with `--strictNullChecks` enabled, i.e. it's no more assignable to `void` than any other type, so might as well not mention it.\r\n\r\nThe former is (maybe?) approximately true, but how about saying _exactly_ what it means? I for one have never been 100% sure and would love to have some clarity. For instance, the [`unknown` type](https://github.com/Microsoft/TypeScript/issues/10715),\r\n\r\n```ts\r\ntype unknown = {} | undefined | null\r\n```\r\n\r\nis supposed to be a \"top\" type, i.e. any value should belong to it. And yet, `void` is not assignable to it.\r\n\r\n```ts\r\ndeclare const v: void\r\nconst foo: unknown = v\r\n// ^^^ Type 'void' is not assignable to type 'unknown'.\r\n```\r\n\r\nWhy is that? According to the above, only `undefined` (and `null`, if no `--strictNullChecks`) inhabit `void`, so why is it not assignable to `unknown`?\r\n\r\nSince [there is no longer a current language specification](https://github.com/Microsoft/TypeScript/issues/14108), it seems the best available documentation is to be found at https://www.typescriptlang.org/docs/home.html, so it would be great if it could give a crisp definition of `void`!","author":{"url":"https://github.com/pelotom","@type":"Person","name":"pelotom"},"datePublished":"2017-11-14T08:14:11Z","url":"https://github.com/microsoft/TypeScript/issues/20006"}
| 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:f49d3ab4-5188-edb0-6ef5-98dc67684bbe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B7EC:31E99C:FDA5E6:1534F68:6B011126 |
| html-safe-nonce | c54672bbf8ff5da36be01bf52c89532b9c66ce2e7dac1286bb3fcc7c7894e424 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCN0VDOjMxRTk5QzpGREE1RTY6MTUzNEY2ODo2QjAxMTEyNiIsInZpc2l0b3JfaWQiOiIxNDUwNzQ1NzIyODAxNTU3Nzk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | dc096238f7a32b12028e0721e23c035a77d67e8cc7f6b4cf31d659e90b4cf6d0 |
| hovercard-subject-tag | issue:273701871 |
| 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/20006/issue_layout |
| twitter:image | https://opengraph.githubassets.com/46e8bbbeae0c7d1410e1b71b401993e9ad9a12c8209471d9ed2c2d4c231c435f/microsoft/TypeScript/issues/20006 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/46e8bbbeae0c7d1410e1b71b401993e9ad9a12c8209471d9ed2c2d4c231c435f/microsoft/TypeScript/issues/20006 |
| og:image:alt | In the handbook, it's stated that void is a little like the opposite of any: the absence of having any type at all. and Declaring variables of type void is not useful because you can only assign un... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pelotom |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width