Title: the types 'T' and (anything else) have no overlap · Issue #32768 · microsoft/TypeScript · GitHub
Open Graph Title: the types 'T' and (anything else) have no overlap · Issue #32768 · microsoft/TypeScript
X Title: the types 'T' and (anything else) have no overlap · Issue #32768 · microsoft/TypeScript
Description: TypeScript Version: 3.5.3 Search Terms: Generic "has no overlap" Code const num = 1; function check
Open Graph Description: TypeScript Version: 3.5.3 Search Terms: Generic "has no overlap" Code const num = 1; function check
X Description: TypeScript Version: 3.5.3 Search Terms: Generic "has no overlap" Code const num = 1; function check<T>(x: T) { return x === num; } check(num); Expected behavior: No error; check ret...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/32768
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"the types 'T' and (anything else) have no overlap","articleBody":"**TypeScript Version:** 3.5.3\r\n\r\n**Search Terms:**\r\n\r\n* Generic \"has no overlap\"\r\n\r\n**Code**\r\n\r\n```ts\r\nconst num = 1;\r\nfunction check\u003cT>(x: T) {\r\n return x === num;\r\n}\r\ncheck(num);\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nNo error; `check` returns `true` if given `num` (or an alias of it), and `false` otherwise.\r\n\r\n**Actual behavior:**\r\n\r\n> ```\r\n> index.ts:3:10 - error TS2367: This condition will always return 'false' since the types 'T' and '1' have no overlap.\r\n>\r\n> 3 return x === num;\r\n> ~~~~~~~~~\r\n>\r\n>\r\n> Found 1 error.\r\n> ```\r\n\r\nI observed this in a slightly more complex case but with the same idea:\r\n\r\n```ts\r\nconst makeNum = () => 1;\r\nfunction check\u003cT>(f: () => T) {\r\n return f === makeNum;\r\n}\r\ncheck(makeNum);\r\n```\r\n\r\n**Playground Link:**\r\nhttps://www.typescriptlang.org/play/#code/MYewdgzgLgBGCuBbGBeGBGA3AKAGbzGCgEtwZgALAU2AGsAeAFQD4AKADwC4ZGBKGAN7YYMAE5Uo8UWBjtUKNAkQ4Avtko1arJb0xA","author":{"url":"https://github.com/davidje13","@type":"Person","name":"davidje13"},"datePublished":"2019-08-08T21:49:25Z","url":"https://github.com/microsoft/TypeScript/issues/32768"}
| 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:02f690cd-337a-c45b-4e1c-7bcdab90fc83 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D976:23CF06:9B575F:C9D73F:6B00E174 |
| html-safe-nonce | a5057ffc990941312db3a1217ef0e933e0e0bd2129ae3ff39e3160eea3ffaa7f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTc2OjIzQ0YwNjo5QjU3NUY6QzlENzNGOjZCMDBFMTc0IiwidmlzaXRvcl9pZCI6IjM0Njk0NDY2NTMzMzE2OTM5NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 98eaae8f9ba126b000efafb114ccba324bb252b6070483c442db771226104065 |
| hovercard-subject-tag | issue:478703235 |
| 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/32768/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5674cd07d85c81f59af9574c373dd81e98cb99c5994370cae8b6a08d3f30b42a/microsoft/TypeScript/issues/32768 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5674cd07d85c81f59af9574c373dd81e98cb99c5994370cae8b6a08d3f30b42a/microsoft/TypeScript/issues/32768 |
| og:image:alt | TypeScript Version: 3.5.3 Search Terms: Generic "has no overlap" Code const num = 1; function check |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | davidje13 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width