Title: Design Meeting Notes, 5/19/2017 · Issue #15957 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 5/19/2017 · Issue #15957 · microsoft/TypeScript
X Title: Design Meeting Notes, 5/19/2017 · Issue #15957 · microsoft/TypeScript
Description: Inference/Generic function composition requests Issues linked to at the bottom. Why are we revisiting this? Ben from RxJS filed an issue about general inference difficulties. Will also be important for function pipeline in the future if ...
Open Graph Description: Inference/Generic function composition requests Issues linked to at the bottom. Why are we revisiting this? Ben from RxJS filed an issue about general inference difficulties. Will also be important...
X Description: Inference/Generic function composition requests Issues linked to at the bottom. Why are we revisiting this? Ben from RxJS filed an issue about general inference difficulties. Will also be important...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/15957
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 5/19/2017","articleBody":"# Inference/Generic function composition requests\r\n\r\nIssues linked to at the bottom.\r\n____________\r\n\r\n* Why are we revisiting this?\r\n * Ben from RxJS filed an issue about general inference difficulties.\r\n * Will also be important for function pipeline in the future if it lands in ES.\r\n* Currently we use inferences from *values* to flow into function parameters\r\n* But we *don't* use the type that the result will flow *into* for inferences.\r\n\r\nExample\r\n\r\n```ts\r\ntype Mapper\u003cT, U> = (x: T) => U;\r\n\r\nfunction wrap\u003cT, U>(cb: Mapper\u003cT, U>): Mapper\u003cT, U> {\r\n return cb;\r\n}\r\n\r\nfunction wrapStringToNumber(cb: Mapper\u003cstring, number>): Mapper\u003cstring, number> {\r\n return cb;\r\n}\r\n\r\n// works (not wrapped in a call)\r\nlet f1: Mapper\u003cstring, number> = s => s.length;\r\n\r\n// works (types are concrete)\r\nlet f2: Mapper\u003cstring, number> = wrapStringToNumber(s => s.length);\r\n\r\n// doesn't work because there are no parameters with known types\r\nlet f3: Mapper\u003cstring, number> = wrap(s => s.length);\r\n```\r\n\r\nWhat you'd like in the last example is that `wrap(...)` draws inferences from its contextual type.\r\n\r\nBut there are some problems with just using the contextual type.\r\n\r\n```ts\r\n// This works\r\nlet a1 = [\"a\", \"b\"].map(s => s.length);\r\n\r\n// This doesn't - requesting the contextual type of `map`'s argument \"fixes\"\r\n// its type parameters which don't have any inferences. This means that `s` gets the right type,\r\n// but `a2` gets the type `Array\u003c{}>`!\r\nlet a2 = [\"a\", \"b\"].map(wrap(s => s.length));\r\n```\r\n\r\nSo basic idea for solution.\r\n\r\n1. Draw inferences from arguments that are not contextually sensitive (e.g. values that are not untyped lambdas that we could give types to).\r\n2. During the *second round* of inference...\r\n * if we run into a a contextually sensitive argument...\r\n * which needs a type parameter which has no inferences...\r\n * then reach out of the call and make inferences from the contextual type to the call's return type\r\n\r\nHarder stuff involves inference between generic type parameters.\r\nNot clear what to do here, but we can tackle it one step at a time.\r\n\r\n_______\r\n\r\n# Default imports for CommonJS modules\r\n\r\nWant to align with Babel's emit - very difficult when people transition to using TypeScript and have to change their imports.\r\n\r\nBiggest problem is that no way to tell which is \"more correct\" when you have a `.d.ts` that has top-level exports - is that a CJS or is it an ES module authored on top of CJS?\r\n\r\nEntire thing needs a proposal.\r\n_______\r\n\r\n## Issues for Composition (instantiate generic signatures using contextual type instead of any)\r\n\r\nOpen:\r\n\r\n* https://github.com/Microsoft/TypeScript/issues/9366\r\n\r\nDuplicates:\r\n\r\n* https://github.com/Microsoft/TypeScript/issues/417\r\n* https://github.com/Microsoft/TypeScript/issues/9107\r\n* https://github.com/Microsoft/TypeScript/issues/9949\r\n* https://github.com/Microsoft/TypeScript/issues/10247\r\n* https://github.com/Microsoft/TypeScript/issues/11311\r\n* https://github.com/Microsoft/TypeScript/issues/11343\r\n* https://github.com/Microsoft/TypeScript/issues/13570\r\n* https://github.com/Microsoft/TypeScript/issues/13632\r\n* https://github.com/Microsoft/TypeScript/issues/15016\r\n\r\n## Inference from return type position\r\n\r\n* https://github.com/Microsoft/TypeScript/issues/11152\r\n* https://github.com/Microsoft/TypeScript/issues/3423\r\n\r\n## Higher order inference with generic functions\r\n\r\n* https://github.com/Microsoft/TypeScript/issues/15680\r\n* https://github.com/Microsoft/TypeScript/issues/10247\r\n\r\n## Comparing generic signatures\r\n\r\nOpen:\r\n* https://github.com/Microsoft/TypeScript/issues/5616\r\n* https://github.com/Microsoft/TypeScript/issues/138\r\n\r\nDuplicates:\r\n\r\n* https://github.com/Microsoft/TypeScript/issues/3038\r\n* https://github.com/Microsoft/TypeScript/issues/3410\r\n* https://github.com/Microsoft/TypeScript/issues/3720\r\n* https://github.com/Microsoft/TypeScript/issues/5251\r\n* https://github.com/Microsoft/TypeScript/issues/8397\r\n* https://github.com/Microsoft/TypeScript/issues/8459\r\n* https://github.com/Microsoft/TypeScript/issues/11537\r\n* https://github.com/Microsoft/TypeScript/issues/11877\r\n* https://github.com/Microsoft/TypeScript/issues/13631\r\n* https://github.com/Microsoft/TypeScript/issues/15458\r\n","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2017-05-19T20:22:07Z","url":"https://github.com/microsoft/TypeScript/issues/15957"}
| 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:949d8b4f-854a-4a3d-7d26-62f0c2d2d983 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E8E2:2E5652:5FB4C5:7BC222:6B00DE63 |
| html-safe-nonce | 5d26d71f434c7dafa40b9009386b2504584eb45bce68024a5b064cd0894ea43f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOEUyOjJFNTY1Mjo1RkI0QzU6N0JDMjIyOjZCMDBERTYzIiwidmlzaXRvcl9pZCI6IjU0NDY3NDIzNDY3ODE3NDQ3MzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6407c6bf3ea832514bd59b66e5fa68a33481d1809bebbe2f76a7d5b5411d96d0 |
| hovercard-subject-tag | issue:230080180 |
| 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/15957/issue_layout |
| twitter:image | https://opengraph.githubassets.com/52767e644da156c0ab56028f29bc24cd7c2f6e5d2fb3770e9ac32c5da5cc3c81/microsoft/TypeScript/issues/15957 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/52767e644da156c0ab56028f29bc24cd7c2f6e5d2fb3770e9ac32c5da5cc3c81/microsoft/TypeScript/issues/15957 |
| og:image:alt | Inference/Generic function composition requests Issues linked to at the bottom. Why are we revisiting this? Ben from RxJS filed an issue about general inference difficulties. Will also be important... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DanielRosenwasser |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width