Title: Type inference of generics is order-dependent · Issue #6627 · microsoft/TypeScript · GitHub
Open Graph Title: Type inference of generics is order-dependent · Issue #6627 · microsoft/TypeScript
X Title: Type inference of generics is order-dependent · Issue #6627 · microsoft/TypeScript
Description: declare var f: { (x: U): U, }; declare function pipe
Open Graph Description: declare var f: { (x: U): U, }; declare function pipe
X Description: declare var f: { <U>(x: U): U, }; declare function pipe<T>(arg: T, dit: (arg: T) => T): T; // welkom in F#! declare function apply<V>(dit: (arg: V) => V, arg: V): V; let n =...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/6627
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type inference of generics is order-dependent","articleBody":"``` ts\ndeclare var f: { \n \u003cU>(x: U): U,\n};\ndeclare function pipe\u003cT>(arg: T, dit: (arg: T) => T): T; // welkom in F#!\ndeclare function apply\u003cV>(dit: (arg: V) => V, arg: V): V;\nlet n = pipe(12, f);\nlet m = apply(f, 12);\n```\n\n`n: number` as desired but `m: {}`. It looks like, during the second pass of type parameter inference for `apply`, the call signature is inferred from `dit`'s argument before it is inferred from `arg`. Since `f` is itself generic, the default is `{}`. @ahejlsberg, is this intended behaviour? It seems like a bug to me.\n\nAlso I am not sure why `getSingleCallSignature` special-cases single-call-signature-only objects. You get yet a different result if you have an extra property on `f`:\n\n``` ts\ndeclare var f: { \n \u003cU>(x: U): U,\n hunch(x: number): number\n};\n...\nlet n = pipe(12, f)\nlet m = apply(f, 12)\n```\n\nNow _both_ `n: any` and `m: any` because getSingleCallSignature doesn't return a signature, so `instantiateTypeWithSingleGenericCallSignature` doesn't do its instantiation at all.\n","author":{"url":"https://github.com/sandersn","@type":"Person","name":"sandersn"},"datePublished":"2016-01-26T18:13:09Z","url":"https://github.com/microsoft/TypeScript/issues/6627"}
| 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:23e04392-c522-5be6-7d09-f7f937e273cf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 965A:14F601:3322EB6:40DB640:6B01BD01 |
| html-safe-nonce | 378b2ca352eeb5ea6fe3fcd8b419953a72446f76181e332d4247b698cc06db7a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjVBOjE0RjYwMTozMzIyRUI2OjQwREI2NDA6NkIwMUJEMDEiLCJ2aXNpdG9yX2lkIjoiNTQwODIzMjQzNzM1MDI1MTc3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bddf85d79f4f2147cb51539cf0e7c257b3af547a833223e8536b3c265961ccd4 |
| hovercard-subject-tag | issue:128897526 |
| 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/6627/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ddb6943ee32e4eb8f274f96ecd80fadc6a58cec277633933564247d4f6389823/microsoft/TypeScript/issues/6627 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ddb6943ee32e4eb8f274f96ecd80fadc6a58cec277633933564247d4f6389823/microsoft/TypeScript/issues/6627 |
| og:image:alt | declare var f: { (x: U): U, }; declare function pipe |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sandersn |
| 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