Title: Proposal for proper top type · Issue #23838 · microsoft/TypeScript · GitHub
Open Graph Title: Proposal for proper top type · Issue #23838 · microsoft/TypeScript
X Title: Proposal for proper top type · Issue #23838 · microsoft/TypeScript
Description: Right now there are three interesting types for unknown values: never can be assigned to anything, but nothing can be assigned to it any can be assigned to anything and anything can be assigned to it unknown can't be assigned to anything...
Open Graph Description: Right now there are three interesting types for unknown values: never can be assigned to anything, but nothing can be assigned to it any can be assigned to anything and anything can be assigned to ...
X Description: Right now there are three interesting types for unknown values: never can be assigned to anything, but nothing can be assigned to it any can be assigned to anything and anything can be assigned to ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/23838
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal for proper top type","articleBody":"Right now there are three interesting types for unknown values:\r\n\r\n`never` can be assigned to anything, but nothing can be assigned to it\r\n`any` can be assigned to anything and anything can be assigned to it\r\n`unknown` can't be assigned to anything, but everything can be assigned to it\r\n\r\nIn type theory terms, `never` is a bottom, `unknown` is a top and `any` is something you don't usually see, but is really handy for a language like TS.\r\n\r\nHere are the properties for `never` and `any`, aside from the abovementioned ones:\r\n\r\n(`A` ranges over all types, including `null` and `undefined`, but excluding `never`, `any`, `{}` and `unknown` itself)\r\n\r\n`A | never = A`\r\n`A & never = never`\r\n`never extends A ? true : false = true`\r\n\r\n`A | any = any`\r\n`A & any = any`\r\n`any extends A ? true : false = true | false`\r\n\r\nNow, I've been using `type unknown = {} | null | undefined` as my top, like most people. It works mostly fine for assignment, but it fails when it comes to unions, intersections and conditionals. For a proper top type, I need the following properties:\r\n\r\n`A | unknown = unknown`\r\n`A & unknown = A`\r\n`unknown extends A ? true : false = false`\r\n\r\nCan we get a type in the language called `unknown` that fits these properties? Another name that might work would be `all`, but I think that's confusing, as the properties it has would confuse people (it's not immediately clear why `A & all = A` in that case.\r\n\r\nIt's become clear to me as of late, I shouldn't use `any` in my code at all, except when I'm absolutely sure I want to turn off type checking. The problem is, a lot of the cases where I use `any`, it's because I need a top type. Especially intersections are hard to deal with, without a top type.","author":{"url":"https://github.com/SimonMeskens","@type":"Person","name":"SimonMeskens"},"datePublished":"2018-05-02T21:36:24Z","url":"https://github.com/microsoft/TypeScript/issues/23838"}
| 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:421b0cd7-128a-d376-8130-5cf988d25067 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E504:13002:71686:8CE6D:6B00F275 |
| html-safe-nonce | ff5268e67f1d4e555000e3961885e421388d300e733d3c902bb490736d061988 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTA0OjEzMDAyOjcxNjg2OjhDRTZEOjZCMDBGMjc1IiwidmlzaXRvcl9pZCI6IjE4NzczNjg5NDMxODY4NjY4MDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4531584a13cec6c90db72b6c420a2aa9bd7bb0d3e26b6aba0ad8f35e3a2f8af9 |
| hovercard-subject-tag | issue:319720914 |
| 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/23838/issue_layout |
| twitter:image | https://opengraph.githubassets.com/962a5bdff1c3ca233a2884df36ffd7092754ff06ee4b413018b0c125fa86a976/microsoft/TypeScript/issues/23838 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/962a5bdff1c3ca233a2884df36ffd7092754ff06ee4b413018b0c125fa86a976/microsoft/TypeScript/issues/23838 |
| og:image:alt | Right now there are three interesting types for unknown values: never can be assigned to anything, but nothing can be assigned to it any can be assigned to anything and anything can be assigned to ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SimonMeskens |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width