Title: Type error when using generic function result as argument, but not when assigned to temp variable first · Issue #35339 · microsoft/TypeScript · GitHub
Open Graph Title: Type error when using generic function result as argument, but not when assigned to temp variable first · Issue #35339 · microsoft/TypeScript
X Title: Type error when using generic function result as argument, but not when assigned to temp variable first · Issue #35339 · microsoft/TypeScript
Description: Issue originally discovered by @eyelidlessness on Gitter. TypeScript Version: 3.8.0-dev.20191123 Search Terms: generic returntype Code declare const foo: < R1, F1 extends () => R1, R2, F2 extends (input: ReturnType
Open Graph Description: Issue originally discovered by @eyelidlessness on Gitter. TypeScript Version: 3.8.0-dev.20191123 Search Terms: generic returntype Code declare const foo: < R1, F1 extends () => R1, R2, F2 extends (...
X Description: Issue originally discovered by @eyelidlessness on Gitter. TypeScript Version: 3.8.0-dev.20191123 Search Terms: generic returntype Code declare const foo: < R1, F1 extends () => R1, R2, F2 ext...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/35339
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type error when using generic function result as argument, but not when assigned to temp variable first","articleBody":"Issue originally discovered by @eyelidlessness on Gitter.\r\n\r\n\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--\u003e\r\n\r\n\u003c!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n--\u003e\r\n**TypeScript Version:** 3.8.0-dev.20191123\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) --\u003e\r\n**Search Terms:** `generic` `returntype`\r\n\r\n**Code**\r\n\r\n```ts\r\ndeclare const foo: \u003c\r\n R1,\r\n F1 extends () =\u003e R1,\r\n R2,\r\n F2 extends (input: ReturnType\u003cF1\u003e) =\u003e R2\r\n\u003e(\r\n f1: F1,\r\n f2: F2\r\n) =\u003e any\r\n\r\nconst f1 = () =\u003e ({ a: 'a' })\r\nconst f2 = (input: { a: string }) =\u003e ({ b: 'b' })\r\n\r\nfoo(f1, f2) // Good\r\n\r\nconst makeF1 = () =\u003e f1;\r\n\r\nfoo(makeF1(), f2) // Good\r\n\r\nconst makeF1p = \u003cT\u003e(t: T) =\u003e f1;\r\n\r\nfoo(\r\n makeF1p(''),\r\n f2 // Error WHY :(\r\n);\r\n\r\nconst made = makeF1p('');\r\n\r\nfoo(\r\n made, // This is fine\r\n f2\r\n)\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nBoth `foo()` calls should compile as the only difference is whether the result of a function call is assigned to a temporary first.\r\n\r\n**Actual behavior:**\r\n\r\nThe first call to `foo()`, where `makeF1p()` is called inline, produces a type error at compile time. The second, where the return value of `makeF1p()` is assigned to temp variable first, compiles fine. The error is:\r\n\r\n```\r\nArgument of type '(input: { a: string; }) =\u003e { b: string; }' is not assignable to parameter of type '(input: unknown) =\u003e unknown'.\r\n Types of parameters 'input' and 'input' are incompatible.\r\n Type 'unknown' is not assignable to type '{ a: string; }'.\r\n```\r\n\r\nIt almost seems like the type parameter inference machinery is leaking outside the scope of the call expression or something? It's weird, at any rate.\r\n\r\n**Playground Link:**\r\n\r\nhttps://www.typescriptlang.org/play/?ts=3.8.0-dev.20191123\u0026ssl=1\u0026ssc=1\u0026pln=33\u0026pc=1#code/CYUwxgNghgTiAEYD2A7AzgF3gMyUgXPADwBQ858ASgIwA0ZFAYtfCAB4YgrBrwAUASngBeAHxU6DcpQBM9CvEYzWHLj34BLFAAcArhkKUQGXTBQAVAJ7aQRZqKFiqMkqL5Sc1Qs3kVsM7xdHcSgUSxISZHQsbBZhfmD+AG94KEIAcih0+ABfAUjUTBxleL4tPQN4FLT4TBgtAHNcxL4UgCMMtuy8iNwkPljaYqEAehH4AHE8YAioooBbKABrEGYRBJFxWIBuXrw+RZXmQSH-UfGppBmC6PhD1eptdaJzN0rzRJ29-o975m0+Ol0gJfOR-PAxvAAKIwGBIGDwADqAAkAJrwfDuAS7G4LKCgdZ-R6A4E4vruBSLUBDSHmAAWGl4jJwWhAHn8JHyQA\r\n\r\n**Related Issues:** I didn't find any, but @jack-williams says #30215 might be the root cause.","author":{"url":"https://github.com/fatcerberus","@type":"Person","name":"fatcerberus"},"datePublished":"2019-11-25T23:26:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/35339/TypeScript/issues/35339"}
| 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:97621ec8-5a2b-e357-5a46-837dc9448398 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 98A2:54B64:130D005:1A9ACE6:6A61C470 |
| html-safe-nonce | 2d7d30e16562f7a95755e9b9277e4152885cf6c3e1d8e0a78c71f2ddfa52d5c7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEEyOjU0QjY0OjEzMEQwMDU6MUE5QUNFNjo2QTYxQzQ3MCIsInZpc2l0b3JfaWQiOiI4Nzk2ODI0Mzg3MDg3MDg0NjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ddc1f0c7b647c61fac329222f383a899902386995b9c7da48478436ead50c463 |
| hovercard-subject-tag | issue:528396890 |
| 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/35339/issue_layout |
| twitter:image | https://opengraph.githubassets.com/759591ac6f47e76b13263cb6b36b02eedf33bf71714229bc80afc6211129b349/microsoft/TypeScript/issues/35339 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/759591ac6f47e76b13263cb6b36b02eedf33bf71714229bc80afc6211129b349/microsoft/TypeScript/issues/35339 |
| og:image:alt | Issue originally discovered by @eyelidlessness on Gitter. TypeScript Version: 3.8.0-dev.20191123 Search Terms: generic returntype Code declare const foo: < R1, F1 extends () => R1, R2, F2 extends (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fatcerberus |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6f4633bcf01c1ad14b73fd07dd39ac31d61f3d3c2578ee08ec1792b7b351eeb9 |
| 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 | ac296ae7f21856f1f92adbad22f870b6fbb4b907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width