Title: Probable bug: Functional properties don't get inferred with circular type parameter constraints like `T extends M
Open Graph Title: Probable bug: Functional properties don't get inferred with circular type parameter constraints like `T extends M
X Title: Probable bug: Functional properties don't get inferred with circular type parameter constraints like `T extends M
Description: TypeScript Version: 4.0.2 Search Terms: Circular type parameter constraint, functional property inference, function parameter inference, function argument inference Code: declare const m: Open Graph Description: TypeScript Version: 4.0.2 Search Terms: Circular type parameter constraint, functional property inference, function parameter inference, function argument inference Code: declare const m: X Description: TypeScript Version: 4.0.2 Search Terms: Circular type parameter constraint, functional property inference, function parameter inference, function argument inference Code: declare const m: <T ext...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/40439
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Probable bug: Functional properties don't get inferred with circular type parameter constraints like `T extends M\u003cT>`","articleBody":"**TypeScript Version:**\r\n4.0.2\r\n\r\n**Search Terms:**\r\nCircular type parameter constraint, functional property inference, function parameter inference, function argument inference\r\n\r\n**Code:**\r\n```typescript\r\ndeclare const m: \u003cT extends M\u003cT>>(m: T) => T\r\ntype M\u003cSelf, K = Exclude\u003ckeyof Self, \"k\" | \"t\">> =\r\n { a?: number\r\n , b?: number\r\n , c?: number\r\n , d?: number\r\n , k?: K\r\n , t?: (k: K) => void\r\n }\r\n\r\n// :)\r\n// Case 1\r\nm({\r\n a: 1,\r\n b: 2,\r\n k: \"a\"\r\n})\r\n\r\n// :)\r\n// Case 2\r\nm({\r\n a: 1,\r\n b: \"x\", // expected error\r\n k: \"c\" // expected error\r\n})\r\n\r\n// :(\r\n// Case 3\r\nm({ // type parameter becomes `unknown` (probably because t's first parameter is `any` initially kinda?)\r\n a: 1,\r\n b: 2,\r\n k: \"a\", \r\n t: k => {} // k is inferred as `never` (instead of `\"a\" | \"b\"`)\r\n})\r\n\r\n// :|\r\n// Case 4\r\nm({\r\n a: 1,\r\n b: 2,\r\n k: \"a\", \r\n t: (k: \"a\" | \"b\") => {} // have to explicitly type `k` which could have been inferred :(\r\n})\r\n```\r\n\r\n**Expected behavior:**\r\nThe parameter `k` of `t` should be inferred as `\"a\" | \"b\"`. As property `k` already gets inferred in Case 1 & 2, so why not the `k` parameter of `t`\r\n\r\n**Actual behavior:**\r\nThe parameter of `t` is inferred as `never` and `T` in inferred as `unknown`. I assume first `T` gets resolved to `unknown` as `t` is initially inferred as `(k: any) => void` which does not satisfy the constraint of `m`.\r\n\r\n[Playground](https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEYD2A7AzgF3gWwFzwB4AVeEADwxBWDXgFliA+RgCj3iIEp4BeRjgFAYAngAcEDAMogIAMwA08ANK94AUTKQArqAIBrEMKSz40uYoBEei-AA+8CxgvNeA+PADe8KAH58KLWwAIxAYN3hFIL94AODQ8MUwaNiQsPdFYGTA1IT4PWilXIxolj18JW4+eAA3JABLYHCAXwEBAHo2+FxOds6AYSg0BABGAWwWD3CofGH5cKD8ACY59zKHKAsBJp7erp6O+AGh+EWxiamZlfgFhzILRQPycTBKYFIYGCQ0vPwLMBtHmRnq93p8wttWgdcCxdkcEABmM5eA4icTwUSwKDYECUGDXcBIbG0AAGWhQehQSAA7ihifAWKJPkEoEEIMJ8WAoFpjhgAOS0WR1GCYdGY7G4+B1ElQFDCOl1FB1DB1KAQNl5BXAXw9dzTeCzeZLK5rCwbRThDD4PS8fgeJrwA7WqWSlCyUJwN6DeDElAgaqhOksBWYEBQN7Gb2mmz2CxBCzEnoQ3a4WywwYIAAsSIu+quN2W4RNZvgFvwpV+GzsDjjlVt9oOAAsoP74BgkKQgRA6mAlerUQhiXo6VSG92G4gkFoIG8my2QlQXW6PiA3tCtpwgA)","author":{"url":"https://github.com/devanshj","@type":"Person","name":"devanshj"},"datePublished":"2020-09-08T20:17:13Z","url":"https://github.com/microsoft/TypeScript/issues/40439"}
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:ebd6214d-bdc5-1e2a-8fc9-bf7a49469879 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id 864C:882E2:B79B9C:F3F155:6B00EC9F html-safe-nonce 01d01d4919ea09c4d5db694bffd422c8178b8b0ac31aadebbcdaa4698e58cdb3 visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjRDOjg4MkUyOkI3OUI5QzpGM0YxNTU6NkIwMEVDOUYiLCJ2aXNpdG9yX2lkIjoiNDQxNzQ1MDY1MTE1NjU0MDU3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac b0854802e0e6c3301399edf3ccb62fde1f80ebfbfcb395cf94f7ac2d3fcf1778 hovercard-subject-tag issue:696148717 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/40439/issue_layout twitter:image https://opengraph.githubassets.com/832b1032df8acb385ee5ec0ed4e6d1f01c0703bcf2701aa3e7f6be35ad16fac7/microsoft/TypeScript/issues/40439 twitter:card summary_large_image og:image https://opengraph.githubassets.com/832b1032df8acb385ee5ec0ed4e6d1f01c0703bcf2701aa3e7f6be35ad16fac7/microsoft/TypeScript/issues/40439 og:image:alt TypeScript Version: 4.0.2 Search Terms: Circular type parameter constraint, functional property inference, function parameter inference, function argument inference Code: declare const m: og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username devanshj hostname github.com expected-hostname github.com None 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc 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 9983dd5da06943f833c971dd5b6bc988e2858be5 ui-target full theme-color #1e2327 color-scheme light dark react-app-name issues
URLs of crawlers that visited me.