Title: To/from assignability is too strict of a check for comparison and other operations · Issue #5300 · microsoft/TypeScript · GitHub
Open Graph Title: To/from assignability is too strict of a check for comparison and other operations · Issue #5300 · microsoft/TypeScript
X Title: To/from assignability is too strict of a check for comparison and other operations · Issue #5300 · microsoft/TypeScript
Description: This can be seen as the dual of #5156 and an extension of #1447. While the former seeked to limit what could be compared, this issue seeks to be more permissive. Currently, the following causes an error: interface I1 { p1: number } inter...
Open Graph Description: This can be seen as the dual of #5156 and an extension of #1447. While the former seeked to limit what could be compared, this issue seeks to be more permissive. Currently, the following causes an ...
X Description: This can be seen as the dual of #5156 and an extension of #1447. While the former seeked to limit what could be compared, this issue seeks to be more permissive. Currently, the following causes an ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/5300
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"To/from assignability is too strict of a check for comparison and other operations","articleBody":"This can be seen as the dual of #5156 and an extension of #1447. While the former seeked to limit what could be compared, this issue seeks to be more permissive.\n\nCurrently, the following causes an error:\n\n``` ts\ninterface I1 {\n p1: number\n}\n\ninterface I2 extends I1 {\n p2: number;\n}\n\nvar x = { p1: 10, p2: 20 };\nvar y: number | I2 = x;\nvar z: I1 = x;\n\n// Error: Operator '===' cannot be applied to types 'number | I2' and 'I1'.\nif (y === z) {\n}\n```\n\nSo while `y` and `z` are both `I2`s at runtime, we restrict the two from comparison.\n\nThis is especially troublesome with my work on string literal types. In trying to use string literal types on our own codebase, I encountered something like the following:\n\n``` ts\ninterface Option {\n type: Map\u003cnumber> | \"string\" | \"boolean\" | \"number\";\n}\ndeclare var opt: Option;\n// ...\n\n// Error: Operator '!==' cannot be applied to types 'Map\u003cnumber> | \"string\" | \"boolean\" | \"number\"' and 'string'.\nif (opt.type !== \"boolean\") {\n //...\n}\nswitch (opt.type) {\n // Error: Type 'string' is not assignable to type 'Map\u003cnumber> | \"string\" | \"boolean\" | \"number\"'.\n case \"string\":\n // ...\n}\n```\n\nOf note: because I use the contextual type to inform string literal types, `\"string\"` in the `case` clause remains having the `string` type. \n","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2015-10-17T02:11:07Z","url":"https://github.com/microsoft/TypeScript/issues/5300"}
| 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:9cce82a4-0b2c-84c6-8711-f677fd78f87b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C406:265430:B09318:F2350C:6AFBE107 |
| html-safe-nonce | 52ce4d5693c57c3736fe4cf452c4dd708b511f5c0b378c219ca0c30a69f8857c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDA2OjI2NTQzMDpCMDkzMTg6RjIzNTBDOjZBRkJFMTA3IiwidmlzaXRvcl9pZCI6Ijc3MTQ3MjM3MjAzMzcyODUzODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3ba13b345da10cda9c42d27d18cb5aa3cf6a72031873bd6f901ff658b9c8d7d8 |
| hovercard-subject-tag | issue:111938757 |
| 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/5300/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e9a3aae0abbc77dfc5ba17e195f3027acc319c5f564258d4d4cdb14b5fb02812/microsoft/TypeScript/issues/5300 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e9a3aae0abbc77dfc5ba17e195f3027acc319c5f564258d4d4cdb14b5fb02812/microsoft/TypeScript/issues/5300 |
| og:image:alt | This can be seen as the dual of #5156 and an extension of #1447. While the former seeked to limit what could be compared, this issue seeks to be more permissive. Currently, the following causes an ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DanielRosenwasser |
| hostname | github.com |
| expected-hostname | github.com |
| None | 744d4381b1c4dbd6d8736c7d7e5bbe7dc11217584e457a3555020c631764e8ec |
| 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 | df859c48a4c8b4c0009c19bb4e82101aacb4b998 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width