Title: Conditional types incorrect for complex types · Issue #35533 · microsoft/TypeScript · GitHub
Open Graph Title: Conditional types incorrect for complex types · Issue #35533 · microsoft/TypeScript
X Title: Conditional types incorrect for complex types · Issue #35533 · microsoft/TypeScript
Description: TypeScript Version: 3.7.2 I'm seeing incorrect behavior when I extend a computed type that's more than a few levels deep. When I explicitly define the type, I don't see the same behavior. I'm guessing that complex types are getting impli...
Open Graph Description: TypeScript Version: 3.7.2 I'm seeing incorrect behavior when I extend a computed type that's more than a few levels deep. When I explicitly define the type, I don't see the same behavior. I'm guess...
X Description: TypeScript Version: 3.7.2 I'm seeing incorrect behavior when I extend a computed type that's more than a few levels deep. When I explicitly define the type, I don't see the same behavio...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/35533
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Conditional types incorrect for complex types","articleBody":"**TypeScript Version:** 3.7.2\r\n\r\nI'm seeing incorrect behavior when I `extend` a computed type that's more than a few levels deep. When I explicitly define the type, I don't see the same behavior. I'm guessing that complex types are getting implicitly cast to `any` in this circumstance – tsc should probably either instantiate the correct type or cast them to `unknown` with a warning when they're too big.\r\n\r\nThis is admittedly a contrived example but I've run into similar issues when, for example, developing https://github.com/ostrowr/ts-json-validator\r\n\r\n**Search Terms:**\r\ndepth, conditional types, extends, implicit any\r\n\r\n**Expected behavior:**\r\n`shouldBeFalse` and `correctlyFalseWhenExpanded` are both `false` (see code snippet below)\r\n\r\n**Actual behavior:**\r\n`shouldBeFalse` is True (i.e. 6 == 5 in my contrived version of Peano arithmetic) \r\n\r\n**Related Issues:**\r\n- https://github.com/microsoft/TypeScript/issues/30152 (maybe related)\r\n- https://github.com/microsoft/TypeScript/issues/29511 (discussion around implicit casts to any)\r\n\r\n**Code**\r\n```ts\r\ntype Natural = { prev: Natural }\r\ntype Zero = { prev: never }\r\n\r\ntype Equals\u003cA extends Natural, B extends Natural> =\r\n A extends B ?\r\n B extends A ?\r\n true :\r\n false : \r\n false\r\n\r\ntype S\u003cT extends Natural> = { prev: T }\r\n\r\ntype One = S\u003cZero>\r\ntype Two = S\u003cOne>\r\ntype Three = S\u003cTwo>\r\ntype Four = S\u003cThree>\r\ntype Five = S\u003cFour>\r\ntype FiveByHand = { // this is the exact same type as Five, just manually expanded\r\n prev: {\r\n prev: {\r\n prev: {\r\n prev: {\r\n prev: {\r\n prev: never;\r\n };\r\n };\r\n };\r\n };\r\n };\r\n}\r\ntype Six = S\u003cFive>\r\ntype SixByHand = { // this is the exact same type as Six, just manually expanded\r\n prev: {\r\n prev: {\r\n prev: {\r\n prev: {\r\n prev: {\r\n prev: {\r\n prev: never;\r\n };\r\n };\r\n };\r\n };\r\n };\r\n };\r\n}\r\ntype correctlyFalseForShallowTypes = Equals\u003cFour, Five> // type: false\r\ntype correctlyTrue = Equals\u003cFour, Four> // type: true\r\ntype shouldBeFalse = Equals\u003cFive, Six> // type: true (should be false!)\r\ntype correctlyFalseWhenExpanded = Equals\u003cFiveByHand, SixByHand> // type: false (as expected)\r\n```\r\n\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Output\u003c/b>\u003c/summary>\r\n\r\n```ts\r\n\"use strict\";\r\n\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n\r\n\u003cdetails>\u003csummary>\u003cb>Compiler Options\u003c/b>\u003c/summary>\r\n\r\n```json\r\n{\r\n \"compilerOptions\": {\r\n \"noImplicitAny\": true,\r\n \"strictNullChecks\": true,\r\n \"strictFunctionTypes\": true,\r\n \"strictPropertyInitialization\": true,\r\n \"strictBindCallApply\": true,\r\n \"noImplicitThis\": true,\r\n \"noImplicitReturns\": true,\r\n \"useDefineForClassFields\": false,\r\n \"alwaysStrict\": true,\r\n \"allowUnreachableCode\": false,\r\n \"allowUnusedLabels\": false,\r\n \"downlevelIteration\": false,\r\n \"noEmitHelpers\": false,\r\n \"noLib\": false,\r\n \"noStrictGenericChecks\": false,\r\n \"noUnusedLocals\": false,\r\n \"noUnusedParameters\": false,\r\n \"esModuleInterop\": true,\r\n \"preserveConstEnums\": false,\r\n \"removeComments\": false,\r\n \"skipLibCheck\": false,\r\n \"checkJs\": false,\r\n \"allowJs\": false,\r\n \"declaration\": true,\r\n \"experimentalDecorators\": false,\r\n \"emitDecoratorMetadata\": false,\r\n \"target\": \"ES2017\",\r\n \"module\": \"ESNext\"\r\n }\r\n}\r\n```\r\n\r\n\r\n\u003c/details>\r\n\r\n**Playground Link:** [Provided](http://www.typescriptlang.org/play/#code/C4TwDgpgBAcghsArgJzgGygXigbymZCANwC5YEV0oBfAKFEigC0JkB7LXfQ0qAO2KsateuGgBRAI6J0AZwA8AQSgQAHsAh8AJrPJJUaADRQAQivWadeymgB8WWlCdRlajdt1mA-I+d+zbpa6yj5+fsDIiNAkvmFQAGZy0VCxCUkiDNAAyvIAKubuVvD66PbYeATEZPl0oowA8gKcOSzstnXQuQDuHNg5jRDtmVC5ABaE0H15PUNiUABibCjNeeMQgx0LAJZEk1A5iyizjPM7ECYgABJw2px4APT3UMCjW7pvz6PQanAAxsBQWRwAC20GGcF0p12xgAVohZADgTcZGg0CBzGAbloIFpUpVeDhUn58WRCXE4iTcETycSeKTqTSKXSqYzWWFKQJdsgANwMtlOai8-l+QV8kVC8mi8W0OjDLJbVQrKEbOUKi7XW7lKCPT4fD4vb6qP4AoGg55zCH7BWw+GI5HoNEYrE4vHMsnkynu1mesUet2+73+4Vsn3B4McwQ8gPCqVh6Vx2OsxNhZOi2VzX5sZCEf5o+ZJRbILKjB1sLq5MS6bBSFEKQ7IYzK+w6zJkRJoWQQTaZ7MQXMgXKRPY1uTyeuNpbIZtPVvPIebWSjJZoLQmCD5jvD6Sj5XGeWqafmyBkCJRKAACkXy60UAARtB252AIQASm7WZzwDzSQA6l8+OIqiYtoOKcCOHZjmc6pYnuapXFih6zo+0DnpaaiQP8OJviIC5wRqN7lK6VQsn6xFeoyoZhpRcZONRNG0mR0ZxhGXISvR8bscm-JcZKbEpnxaZAA)","author":{"url":"https://github.com/ostrowr","@type":"Person","name":"ostrowr"},"datePublished":"2019-12-06T00:44:17Z","url":"https://github.com/microsoft/TypeScript/issues/35533"}
| 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:f7609682-2042-42dc-4660-21304a4cf355 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3DE:EDA7A:2A975B4:361E1C6:6B01AA6B |
| html-safe-nonce | 8499a245e6e9cd539e48f1c2a447a9898fec25567021d117e8d163dad7595a13 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0RFOkVEQTdBOjJBOTc1QjQ6MzYxRTFDNjo2QjAxQUE2QiIsInZpc2l0b3JfaWQiOiI2OTg4NDgwNDkzMzAxOTAxOTMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 68ba7467341d256a414bcc7f9bd99690e6d71cd936b4d2b56b1aed7cc2e10644 |
| hovercard-subject-tag | issue:533680031 |
| 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/35533/issue_layout |
| twitter:image | https://opengraph.githubassets.com/99c89e54c4e920992fe75febf701f4e5fb0f873ecb6258d666e39361ae4e00fd/microsoft/TypeScript/issues/35533 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/99c89e54c4e920992fe75febf701f4e5fb0f873ecb6258d666e39361ae4e00fd/microsoft/TypeScript/issues/35533 |
| og:image:alt | TypeScript Version: 3.7.2 I'm seeing incorrect behavior when I extend a computed type that's more than a few levels deep. When I explicitly define the type, I don't see the same behavior. I'm guess... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ostrowr |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width