Title: [Regression] ReturnType<> Inference works on 3.3.3, breaks on 3.4.1, 3.5.1 · Issue #31814 · microsoft/TypeScript · GitHub
Open Graph Title: [Regression] ReturnType<> Inference works on 3.3.3, breaks on 3.4.1, 3.5.1 · Issue #31814 · microsoft/TypeScript
X Title: [Regression] ReturnType<> Inference works on 3.3.3, breaks on 3.4.1, 3.5.1 · Issue #31814 · microsoft/TypeScript
Description: TypeScript Version: 3.4.1, 3.5.1 Search Terms: regression, ReturnType, parameter, inference Code interface Mapper
Open Graph Description: TypeScript Version: 3.4.1, 3.5.1 Search Terms: regression, ReturnType, parameter, inference Code interface Mapper
X Description: TypeScript Version: 3.4.1, 3.5.1 Search Terms: regression, ReturnType, parameter, inference Code interface Mapper<HandledInputT, OutputT> { (name : string, mixed : HandledInputT) : OutputT, }...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/31814
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Regression] ReturnType\u003c> Inference works on 3.3.3, breaks on 3.4.1, 3.5.1","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:** 3.4.1, 3.5.1\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** regression, ReturnType, parameter, inference\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface Mapper\u003cHandledInputT, OutputT> {\r\n (name : string, mixed : HandledInputT) : OutputT,\r\n}\r\n\r\n\r\nexport type IsPipeable\u003c\r\n FromF extends Mapper\u003cany, any>,\r\n ToF extends Mapper\u003cany, any>\r\n> = (\r\n ToF extends Mapper\u003cinfer HandledInputT, any> ?\r\n (\r\n ReturnType\u003cFromF> extends HandledInputT ?\r\n true :\r\n false\r\n ) :\r\n false\r\n);\r\n\r\nexport type AssertPipeable\u003c\r\n FromF extends Mapper\u003cany, any>,\r\n ToF extends Mapper\u003cany, any>\r\n> = (\r\n IsPipeable\u003cFromF, ToF> extends true ?\r\n ToF :\r\n [ReturnType\u003cFromF>, \"is not pipeable\"]\r\n);\r\n\r\ndeclare function pipe\u003c\r\n F0 extends Mapper\u003cunknown, any>,\r\n F1 extends Mapper\u003cany, any>\r\n> (\r\n f0 : F0,\r\n f1 : AssertPipeable\u003cF0, F1>\r\n): void;\r\n\r\ndeclare function literal\u003cArrT extends (string | number | boolean | bigint | null | undefined)[]>(\r\n ...arr: ArrT\r\n): (\r\n Mapper\u003cunknown, ArrT[Extract\u003ckeyof ArrT, number>]>\r\n);\r\ndeclare const b: Mapper\u003c\"0\" | \"1\" | 0 | 1 | \"false\" | \"true\", boolean>\r\n\r\n//TS suddenly thinks the first arg is Mapper\u003cunknown, any>.\r\n//It is actually Mapper\u003cunknown, \"0\" | \"1\" | 0 | 1 | \"false\" | \"true\">.\r\npipe(\r\n //TS knows this is Mapper\u003cunknown, \"0\" | \"1\" | 0 | 1 | \"false\" | \"true\">\r\n literal(\"0\", \"1\", 0, 1, \"false\", \"true\"),\r\n /*\r\n Expected: works.\r\n Actual:\r\n Argument of type 'Mapper\u003c0 | \"0\" | \"1\" | 1 | \"false\" | \"true\", boolean>'\r\n is not assignable to parameter of type '[any, \"is not pipeable\"]'.\r\n\r\n Succeeds with 3.3.3,\r\n Fails with 3.4.1,\r\n Fails with 3.5.1\r\n */\r\n b\r\n);\r\n\r\nconst a = literal(\"0\", \"1\", 0, 1, \"false\", \"true\");\r\n//TS now knows the first arg is Mapper\u003cunknown, \"0\" | \"1\" | 0 | 1 | \"false\" | \"true\">\r\npipe(\r\n a,\r\n /*\r\n This works.\r\n `a` is literally the same type as\r\n `literal(\"0\", \"1\", 0, 1, \"false\", \"true\")`.\r\n\r\n Why would the first pipe() call fail,\r\n but the second one succeed?\r\n\r\n Succeeds with 3.3.3,\r\n Succeeds with 3.4.1,\r\n Succeeds with 3.5.1\r\n */\r\n b\r\n);\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nThe below should work,\r\n\r\n```ts\r\npipe(\r\n literal(\"0\", \"1\", 0, 1, \"false\", \"true\"),\r\n b\r\n);\r\n```\r\n\r\n**Actual behavior:**\r\n\r\nIt used to work but does not work now.\r\n\r\n**Playground Link:** [Playground](http://www.typescriptlang.org/play/#src=interface%20Mapper%3CHandledInputT%2C%20OutputT%3E%20%7B%0D%0A%20%20%20%20(name%20%3A%20string%2C%20mixed%20%3A%20HandledInputT)%20%3A%20OutputT%2C%0D%0A%7D%0D%0A%0D%0A%0D%0Aexport%20type%20IsPipeable%3C%0D%0A%20%20%20%20FromF%20extends%20Mapper%3Cany%2C%20any%3E%2C%0D%0A%20%20%20%20ToF%20extends%20Mapper%3Cany%2C%20any%3E%0D%0A%3E%20%3D%20(%0D%0A%20%20%20%20ToF%20extends%20Mapper%3Cinfer%20HandledInputT%2C%20any%3E%20%3F%0D%0A%20%20%20%20(%0D%0A%20%20%20%20%20%20%20%20ReturnType%3CFromF%3E%20extends%20HandledInputT%20%3F%0D%0A%20%20%20%20%20%20%20%20true%20%3A%0D%0A%20%20%20%20%20%20%20%20false%0D%0A%20%20%20%20)%20%3A%0D%0A%20%20%20%20false%0D%0A)%3B%0D%0A%0D%0Aexport%20type%20AssertPipeable%3C%0D%0A%20%20%20%20FromF%20extends%20Mapper%3Cany%2C%20any%3E%2C%0D%0A%20%20%20%20ToF%20extends%20Mapper%3Cany%2C%20any%3E%0D%0A%3E%20%3D%20(%0D%0A%20%20%20%20IsPipeable%3CFromF%2C%20ToF%3E%20extends%20true%20%3F%0D%0A%20%20%20%20ToF%20%3A%0D%0A%20%20%20%20%5BReturnType%3CFromF%3E%2C%20%22is%20not%20pipeable%22%5D%0D%0A)%3B%0D%0A%0D%0Adeclare%20function%20pipe%3C%0D%0A%20%20%20%20F0%20extends%20Mapper%3Cunknown%2C%20any%3E%2C%0D%0A%20%20%20%20F1%20extends%20Mapper%3Cany%2C%20any%3E%0D%0A%3E%20(%0D%0A%20%20%20%20f0%20%3A%20F0%2C%0D%0A%20%20%20%20f1%20%3A%20AssertPipeable%3CF0%2C%20F1%3E%0D%0A)%3A%20void%3B%0D%0A%0D%0Adeclare%20function%20literal%3CArrT%20extends%20(string%20%7C%20number%20%7C%20boolean%20%7C%20bigint%20%7C%20null%20%7C%20undefined)%5B%5D%3E(%0D%0A%20%20%20%20...arr%3A%20ArrT%0D%0A)%3A%20(%0D%0A%20%20%20%20Mapper%3Cunknown%2C%20ArrT%5BExtract%3Ckeyof%20ArrT%2C%20number%3E%5D%3E%0D%0A)%3B%0D%0Adeclare%20const%20b%3A%20Mapper%3C%220%22%20%7C%20%221%22%20%7C%200%20%7C%201%20%7C%20%22false%22%20%7C%20%22true%22%2C%20boolean%3E%0D%0A%0D%0A%2F%2FTS%20suddenly%20thinks%20the%20first%20arg%20is%20Mapper%3Cunknown%2C%20any%3E.%0D%0A%2F%2FIt%20is%20actually%20Mapper%3Cunknown%2C%20%220%22%20%7C%20%221%22%20%7C%200%20%7C%201%20%7C%20%22false%22%20%7C%20%22true%22%3E.%0D%0Apipe(%0D%0A%20%20%20%20%2F%2FTS%20knows%20this%20is%20Mapper%3Cunknown%2C%20%220%22%20%7C%20%221%22%20%7C%200%20%7C%201%20%7C%20%22false%22%20%7C%20%22true%22%3E%0D%0A%20%20%20%20literal(%220%22%2C%20%221%22%2C%200%2C%201%2C%20%22false%22%2C%20%22true%22)%2C%0D%0A%20%20%20%20%2F*%0D%0A%20%20%20%20%20%20%20%20Expected%3A%20works.%0D%0A%20%20%20%20%20%20%20%20Actual%3A%0D%0A%20%20%20%20%20%20%20%20Argument%20of%20type%20'Mapper%3C0%20%7C%20%220%22%20%7C%20%221%22%20%7C%201%20%7C%20%22false%22%20%7C%20%22true%22%2C%20boolean%3E'%0D%0A%20%20%20%20%20%20%20%20is%20not%20assignable%20to%20parameter%20of%20type%20'%5Bany%2C%20%22is%20not%20pipeable%22%5D'.%0D%0A%0D%0A%20%20%20%20%20%20%20%20Succeeds%20with%203.3.3%2C%0D%0A%20%20%20%20%20%20%20%20Fails%20with%203.4.1%2C%0D%0A%20%20%20%20%20%20%20%20Fails%20with%203.5.1%0D%0A%20%20%20%20*%2F%0D%0A%20%20%20%20b%0D%0A)%3B%0D%0A%0D%0Aconst%20a%20%3D%20literal(%220%22%2C%20%221%22%2C%200%2C%201%2C%20%22false%22%2C%20%22true%22)%3B%0D%0A%2F%2FTS%20now%20knows%20the%20first%20arg%20is%20Mapper%3Cunknown%2C%20%220%22%20%7C%20%221%22%20%7C%200%20%7C%201%20%7C%20%22false%22%20%7C%20%22true%22%3E%0D%0Apipe(%0D%0A%20%20%20%20a%2C%0D%0A%20%20%20%20%2F*%0D%0A%20%20%20%20%20%20%20%20This%20works.%0D%0A%20%20%20%20%20%20%20%20%60a%60%20is%20literally%20the%20same%20type%20as%0D%0A%20%20%20%20%20%20%20%20%60literal(%220%22%2C%20%221%22%2C%200%2C%201%2C%20%22false%22%2C%20%22true%22)%60.%0D%0A%0D%0A%20%20%20%20%20%20%20%20Why%20would%20the%20first%20pipe()%20call%20fail%2C%0D%0A%20%20%20%20%20%20%20%20but%20the%20second%20one%20succeed%3F%0D%0A%0D%0A%20%20%20%20%20%20%20%20Succeeds%20with%203.3.3%2C%0D%0A%20%20%20%20%20%20%20%20Succeeds%20with%203.4.1%2C%0D%0A%20%20%20%20%20%20%20%20Succeeds%20with%203.5.1%0D%0A%20%20%20%20*%2F%0D%0A%20%20%20%20b%0D%0A)%3B)\r\n\r\n**Related Issues:**\r\n\r\nI feel like it is related to #29133 somehow. Because I have `ReturnType\u003c>` being used in a parameter again. But it's somewhat different this time in that the first argument is not an anonymous function \"literal\" I created. It's a function given by another function.\r\n","author":{"url":"https://github.com/AnyhowStep","@type":"Person","name":"AnyhowStep"},"datePublished":"2019-06-07T08:13:32Z","url":"https://github.com/microsoft/TypeScript/issues/31814"}
| 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:8df731a4-0fe9-25fc-7cd7-cb1c8978cb0b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC32:1D86C4:2CC1B58:38E21DD:6B01B588 |
| html-safe-nonce | 292807ef4ca074ffb34dd31ef8e444a857ee9327ebdb652745c0289bab85277b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzMyOjFEODZDNDoyQ0MxQjU4OjM4RTIxREQ6NkIwMUI1ODgiLCJ2aXNpdG9yX2lkIjoiMTQ5NDM0ODkxNzk4NTM1OTI0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d049e2d9414a869fb5c42cd58f2c4a02d50c7b6924c18a42d7392c1a37c0f18e |
| hovercard-subject-tag | issue:453391389 |
| 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/31814/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3c49420e71dec4d147c658626d9581c0bc5c90445a020adfda507df84eb24fc4/microsoft/TypeScript/issues/31814 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3c49420e71dec4d147c658626d9581c0bc5c90445a020adfda507df84eb24fc4/microsoft/TypeScript/issues/31814 |
| og:image:alt | TypeScript Version: 3.4.1, 3.5.1 Search Terms: regression, ReturnType, parameter, inference Code interface Mapper |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AnyhowStep |
| 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