Title: Generic not inferred from contextual types · Issue #25293 · microsoft/TypeScript · GitHub
Open Graph Title: Generic not inferred from contextual types · Issue #25293 · microsoft/TypeScript
X Title: Generic not inferred from contextual types · Issue #25293 · microsoft/TypeScript
Description: TypeScript Version: 2.9.2 Search Terms: generic infer contextual type Code const baz: (n: number) => number = ( // param `n` is correctly inferred to be `number` :-) n => n ); const identity =
Open Graph Description: TypeScript Version: 2.9.2 Search Terms: generic infer contextual type Code const baz: (n: number) => number = ( // param `n` is correctly inferred to be `number` :-) n => n ); const identity =
X Description: TypeScript Version: 2.9.2 Search Terms: generic infer contextual type Code const baz: (n: number) => number = ( // param `n` is correctly inferred to be `number` :-) n => n ); const identity ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/25293
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic not inferred from contextual types","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--\u003e\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. --\u003e\r\n**TypeScript Version:** 2.9.2\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 infer contextual type\r\n\r\n**Code**\r\n\r\n```ts\r\nconst baz: (n: number) =\u003e number = (\r\n // param `n` is correctly inferred to be `number` :-)\r\n n =\u003e n\r\n);\r\n\r\nconst identity = \u003cT\u003e(t: T) =\u003e t;\r\n\r\nconst bar: (n: number) =\u003e number = identity(\r\n // param `n` is inferred as `any`, expected `number` :-(\r\n x =\u003e x\r\n);\r\n```\r\n\r\n**Expected behavior:** TypeScript should infer the generic `T` in `identity` from the contextual type.\r\n\r\n**Actual behavior:** TypeScript infers the generic `T` in `identity` as `any`!\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior --\u003e \r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? --\u003e\r\n","author":{"url":"https://github.com/OliverJAsh","@type":"Person","name":"OliverJAsh"},"datePublished":"2018-06-28T13:20:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/25293/TypeScript/issues/25293"}
| 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:9a8ae9fd-bb4b-9856-8620-60edb9e54635 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A726:B1596:3E0506:5966FE:6A61E67F |
| html-safe-nonce | 49462205c2bd17435aaa9b749266eb6956ef434c378c7306453b287e776a5975 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzI2OkIxNTk2OjNFMDUwNjo1OTY2RkU6NkE2MUU2N0YiLCJ2aXNpdG9yX2lkIjoiODQ1OTAzMzIzMzM3MjM0MTg4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f9c72d5550436d7f74bd856884843ccacd8075697792a376d3453ec95234c333 |
| hovercard-subject-tag | issue:336618621 |
| 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/25293/issue_layout |
| twitter:image | https://opengraph.githubassets.com/203052ac2a3ee218a815238a1cfde6fb01f6a484a93ec97545b88436650f704d/microsoft/TypeScript/issues/25293 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/203052ac2a3ee218a815238a1cfde6fb01f6a484a93ec97545b88436650f704d/microsoft/TypeScript/issues/25293 |
| og:image:alt | TypeScript Version: 2.9.2 Search Terms: generic infer contextual type Code const baz: (n: number) => number = ( // param `n` is correctly inferred to be `number` :-) n => n ); const identity = |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | OliverJAsh |
| hostname | github.com |
| expected-hostname | github.com |
| None | b2de8c74e5e61e893155ba46ee41bc66170c1644cb795adefa8386d490f7781c |
| 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 | d1866027ded575df8a15c731dd8b9986c9483ceb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width