Title: Typescript forbids safety checks that check equality of values with different generic types · Issue #17445 · microsoft/TypeScript · GitHub
Open Graph Title: Typescript forbids safety checks that check equality of values with different generic types · Issue #17445 · microsoft/TypeScript
X Title: Typescript forbids safety checks that check equality of values with different generic types · Issue #17445 · microsoft/TypeScript
Description: TypeScript Version: 2.4.2 When a function is passed two arguments of two different generic types, there exists the possibility that the two generic types are in fact the same type and that the two values are the same value. A function sh...
Open Graph Description: TypeScript Version: 2.4.2 When a function is passed two arguments of two different generic types, there exists the possibility that the two generic types are in fact the same type and that the two ...
X Description: TypeScript Version: 2.4.2 When a function is passed two arguments of two different generic types, there exists the possibility that the two generic types are in fact the same type and that the two ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/17445
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Typescript forbids safety checks that check equality of values with different generic types","articleBody":"\u003c!-- BUGS: Please use this template. -->\r\n\u003c!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n\u003c!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n**TypeScript Version:** 2.4.2\r\n\r\nWhen a function is passed two arguments of two different generic types, there exists the possibility that the two generic types are in fact the same type and that the two values are the same value. A function should be able to test for this case and handle it appropriately, especially when ensuring the two values are different is essential to a safety condition. However, typescript forbids us from making this comparison.\r\n\r\n**Code**\r\n\r\n```ts\r\n// 'Operator '===' cannot be applied to types 'T' and 'U'.'\r\nfunction test\u003cT, U>(a: T, b: U): void {\r\n if (a === b) {\r\n // The caller set T and U to the same type and 'a' and 'b' to the same value.\r\n // Take apprpriate action\r\n }\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nAllow the comparison, perhaps with a TSLint warning asking me if I'm sure I want to do this.\r\n\r\n**Actual behavior:**\r\n\r\n'Operator '===' cannot be applied to types 'T' and 'U'.'\r\n\r\nForcing me to make workaround of\r\n\r\n```ts\r\n// Workaround using the three-letter profanity eschewed by all righteous TypeScript programmers\r\nfunction test\u003cT, U>(a: T, b: U): void {\r\n if (a === (b as any)) {\r\n // The caller set T and U to the same type and 'a' and 'b' to the same value.\r\n // Take apprpriate action\r\n }\r\n}\r\n```\r\n","author":{"url":"https://github.com/UppaJung","@type":"Person","name":"UppaJung"},"datePublished":"2017-07-27T05:04:55Z","url":"https://github.com/microsoft/TypeScript/issues/17445"}
| 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:9b841f31-ec8f-9df9-667d-c6b545377dce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACF4:1D86C4:8835C6:AE87C0:6B00EA65 |
| html-safe-nonce | dace6f93985303ca8110a86f606121908d0961992eb6ad7c718d0e96a684827e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0Y0OjFEODZDNDo4ODM1QzY6QUU4N0MwOjZCMDBFQTY1IiwidmlzaXRvcl9pZCI6IjU0NDE3Nzc4ODg1NzM1ODE5MjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 927cec9b1f6adf67f56508041d7f030d168377bc4e4bb6a4800e7c6a42b9a672 |
| hovercard-subject-tag | issue:245926751 |
| 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/17445/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0c6dae620bb598d226b34450c9ed7cd6d46b41f5b132dce0c98d5daa3be788bc/microsoft/TypeScript/issues/17445 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0c6dae620bb598d226b34450c9ed7cd6d46b41f5b132dce0c98d5daa3be788bc/microsoft/TypeScript/issues/17445 |
| og:image:alt | TypeScript Version: 2.4.2 When a function is passed two arguments of two different generic types, there exists the possibility that the two generic types are in fact the same type and that the two ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | UppaJung |
| 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