Title: Covariance breaks when checking for `undefinded` in a type · Issue #55161 · microsoft/TypeScript · GitHub
Open Graph Title: Covariance breaks when checking for `undefinded` in a type · Issue #55161 · microsoft/TypeScript
X Title: Covariance breaks when checking for `undefinded` in a type · Issue #55161 · microsoft/TypeScript
Description: Bug Report I'm using the solid-js npm package which defines a type called Setter: type Setter
Open Graph Description: Bug Report I'm using the solid-js npm package which defines a type called Setter: type Setter X Description: Bug Report I'm using the solid-js npm package which defines a type called Setter: type Setter<T> = (undefined extends T ? () => undefined : {}) & (<U extends T>(value: (prev:...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/55161
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Covariance breaks when checking for `undefinded` in a type","articleBody":"# Bug Report\r\n\r\nI'm using the `solid-js` npm package which defines a type called `Setter`:\r\n```ts\r\ntype Setter\u003cT> = (undefined extends T ? () => undefined : {}) & (\u003cU extends T>(value: (prev: T) => U) => U) & (\u003cU extends T>(value: Exclude\u003cU, Function>) => U) & (\u003cU extends T>(value: Exclude\u003cU, Function> | ((prev: T) => U)) => U);\r\n```\r\nI don't fully understand the reasoning behind it, but it's giving me some problems:\r\n```ts\r\ntype Setter\u003cT> = (undefined extends T ? () => undefined : {}) & (\u003cU extends T>(value: (prev: T) => U) => U) & (\u003cU extends T>(value: Exclude\u003cU, Function>) => U) & (\u003cU extends T>(value: Exclude\u003cU, Function> | ((prev: T) => U)) => U);\r\n\r\nclass A { a = 1 }\r\nclass B extends A { b = 2 }\r\n\r\ntype Test\u003cT> = { 0: Setter\u003cT> };\r\n\r\ndeclare const a: Test\u003cA>;\r\nconst b: Test\u003cB> = a; // ERROR!\r\n```\r\nI created an object with the property `0` which contains a `Setter` and it appears to not be covariant.\r\nInspecting the error it looks like that the problem is originated from this part `undefined extends T ? () => undefined : {}`, infact if I remove it this works, moreover the problem would still occur if that was the only part of the type:\r\n```ts\r\ntype Setter\u003cT> = undefined extends T ? () => undefined : {};\r\n\r\nclass A { a = 1 }\r\nclass B extends A { b = 2 }\r\n\r\ntype Test\u003cT> = { 0: Setter\u003cT> };\r\n\r\ndeclare const a: Test\u003cA>;\r\nconst b: Test\u003cB> = a; // ERROR!\r\n```\r\nI think it is an error because the types are the same:\r\n```ts\r\ntype TA = Test\u003cA>;\r\n// ^? type TA = { 0: {}; }\r\ntype TB = Test\u003cB>;\r\n// ^? type TB = { 0: {}; }\r\n```\r\nAdditionally if `Test` were to be defined as `[ Setter\u003cT> ]` the error would not occur:\r\n```ts\r\ntype Setter\u003cT> = undefined extends T ? () => undefined : {};\r\n\r\nclass A { a = 1 }\r\nclass B extends A { b = 2 }\r\n\r\ntype Test\u003cT> = [ Setter\u003cT> ];\r\n\r\ndeclare const a: Test\u003cA>;\r\nconst b: Test\u003cB> = a; // OK?!?!\r\n```\r\n\r\n### 🔎 Search Terms\r\n\r\n- undefined extends T\r\n- covariance\r\n- covariant\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nThis changed between versions **3.3.3** and **3.5.1**. (The only playground version in which it doesn't occur is **3.3.3**)\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground Link](https://www.typescriptlang.org/play?#code/LAKFBcE8AcFMAIDKtzlgJwDwBUB88BeeACgFcA7AE1gDMBLc2S+WADzSoGd5t4B+EgEpC+CtXqNmALngBvAL7CAZCUwBVFu1hceuYgDcAhgBtSsGcWjpY+mdmEF8ah0+WqNbDpW54DJszIAoqwAxqbU6gA08ABiFCHgdAD25Lgu8M7wKsTqml4+ekam5vDBYaQRatFx5AnJqfAAPiSW1rY86c6dggDcoAD0-fBQcEgoaFh4hO552t66fsUWVjZ23SIZbjkeWjq+RQGloeGwUbHxiSlpG5nZuZ5zBYuHZSdnNXVXTS0r7fY3gm6fRAg2GMAQyFQGBw+CIYloDCYsz2-CEG3hEiRMgUwNAYUMnG4AEE5PBDNMAIzweR44wE7gAIWR8xJsngACNpgAmamgCDgniwTjgGHTNkABhkkImovkwNBIwQ2CFIqmRAA2mMoZN8ABdXEgaj46zwEIpYVkuwqzBE3DAs3kC3sq3CzAM2FknrwUGBABKvoA8r6AIR8kCKngkojK122+VDeDwAB6fH5o2wTOj1vd8cTyb4QA)\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ntype Setter\u003cT> = (undefined extends T ? () => undefined : {}) & (\u003cU extends T>(value: (prev: T) => U) => U) & (\u003cU extends T>(value: Exclude\u003cU, Function>) => U) & (\u003cU extends T>(value: Exclude\u003cU, Function> | ((prev: T) => U)) => U);\r\n// type Setter\u003cT> = (\u003cU extends T>(value: (prev: T) => U) => U) & (\u003cU extends T>(value: Exclude\u003cU, Function>) => U) & (\u003cU extends T>(value: Exclude\u003cU, Function> | ((prev: T) => U)) => U);\r\n// type Setter\u003cT> = undefined extends T ? () => undefined : {};\r\n\r\nclass A { a = 1 }\r\nclass B extends A { b = 2 }\r\n\r\ntype Test\u003cT> = { 0: Setter\u003cT> };\r\n// type Test\u003cT> = [ Setter\u003cT> ];\r\n\r\ndeclare const a: Test\u003cA>;\r\nconst b: Test\u003cB> = a; // ERROR!\r\n\r\ntype TA = Test\u003cA>;\r\n// ^?\r\ntype TB = Test\u003cB>;\r\n// ^?\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nCan't assign `b` with the value of `a`.\r\nIt is wrong at the very least because it is not consistent\r\n\r\n### 🙂 Expected behavior\r\n\r\nCan assign `b` with the value of `a`\r\n","author":{"url":"https://github.com/AFatNiBBa","@type":"Person","name":"AFatNiBBa"},"datePublished":"2023-07-26T14:02:50Z","url":"https://github.com/microsoft/TypeScript/issues/55161"}
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:16b6a1b7-1f89-d3d5-b6d4-c00a872917d6 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id 923E:3E4205:1B8525D:24C0CFF:6B0163DD html-safe-nonce 6c30f4a8961b239f398658298736246a06de3af109bbb91732e1987c509d9643 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjNFOjNFNDIwNToxQjg1MjVEOjI0QzBDRkY6NkIwMTYzREQiLCJ2aXNpdG9yX2lkIjoiNzEwNTc3NTI4MTM1NjQ5Nzg4NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac f06e522fd49f9ae8c4cd4a431278dd4cffb29afd7ded6b2fff5ebe8779ad9894 hovercard-subject-tag issue:1822490674 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/55161/issue_layout twitter:image https://opengraph.githubassets.com/c31f4eafabf4c1caab1adaff7e95c7711e5018922bb685334045c5a452a30965/microsoft/TypeScript/issues/55161 twitter:card summary_large_image og:image https://opengraph.githubassets.com/c31f4eafabf4c1caab1adaff7e95c7711e5018922bb685334045c5a452a30965/microsoft/TypeScript/issues/55161 og:image:alt Bug Report I'm using the solid-js npm package which defines a type called Setter: type Setter og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username AFatNiBBa 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
URLs of crawlers that visited me.