Title: Design Meeting Notes, 8/24/2018 · Issue #26952 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 8/24/2018 · Issue #26952 · microsoft/TypeScript
X Title: Design Meeting Notes, 8/24/2018 · Issue #26952 · microsoft/TypeScript
Description: Call-site inference for implicit anys This is a demo presentation [[Opens up minimatch]] "This is the codebase you open up to make yourself feel good about JavaScript" Looking at the charSet declaration function We have noImplicitAny on ...
Open Graph Description: Call-site inference for implicit anys This is a demo presentation [[Opens up minimatch]] "This is the codebase you open up to make yourself feel good about JavaScript" Looking at the charSet declar...
X Description: Call-site inference for implicit anys This is a demo presentation [[Opens up minimatch]] "This is the codebase you open up to make yourself feel good about JavaScript" Looking at the char...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/26952
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 8/24/2018","articleBody":"# Call-site inference for implicit `any`s\r\n\r\nThis is a demo presentation\r\n\r\n* \\[\\[Opens up minimatch]]\r\n* \"This is the codebase you open up to make yourself feel good about JavaScript\"\r\n* Looking at the `charSet` declaration function\r\n * We have `noImplicitAny` on\r\n * See that it was at some point called with a `string`, and so we change the parameter type.\r\n * If we observe a circularity, we fall back to `any` and report an error.\r\n* Is this TypeScript too?\r\n * It works for either JavaScript or TypeScript\r\n* How bad is it?\r\n * The graphs are confusing, but it's over 4.5x slower to look at how the function itself is called to figure out the parameter types.\r\n * If you only look at use-sites of parameters within the bodies of functions, it'x ~1.8x slower.\r\n* We mostly imagine that this would be a one-time shot tool\r\n* Could also imagine that we'd improve the performance here, but it's decent\r\n* Did we look at the tests at all? You'd figure unit tests would be great for figuring out use-site.\r\n * But that's a problem for stupid tests like \"assert that this throws when I pass in a number\"\r\n* But you get 40% more type coverage on Webpack.\r\n * That's like half the way there.\r\n * But even that's not worth slowing down the type-checker so dramatically.\r\n * Seems like we should be leveraging this *somehow*.\r\n\r\n# Weird behavior for spreading arrayish types\r\n\r\n#26110\r\n\r\n* We now allow rest parameters to have a generic type (`T`).\r\n * The requirement has been that that generic type needs to extend an array (e.g. `T extends any[]`).\r\n* But you can come up with several things that actually satisfy arrays.\r\n * Object subtypes:\r\n\r\n ```ts\r\n interface CoolArray extends Array\u003cstring>\r\n function foo\u003cT extends any[]>(...args: T): T {\r\n throw 0;\r\n }\r\n foo\u003cCoolArray>();\r\n ```\r\n* Problem: what does it mean to spread in these object subtypes?\r\n * For these object subtypes, any argument list translated to an array or a tuple won't ever satisfy these types.\r\n* Solution: if you ever have a type parameter constrained to something other than an `Array` or `ReadonlyArray`, and you are trying to relate to a generic rest parameter, you infer a tuple type from the matching argument and try to infer from that.\r\n * If that inference fails, TypeScript falls back to the constraint and relates against that.\r\n\r\n* Union subtypes:\r\n\r\n ```ts\r\n function foo\u003cT extends [] | [number, number]> (...args: T): T {\r\n throw 0;\r\n }\r\n foo\u003cCoolArray>();\r\n ```\r\n\r\n# Named type arguments, associated types, and partial inference\r\n\r\n* In #23696, we realized that making every type parameter nameable would be problematic for existing APIs - it exposes what were thought of as mostly implementation details.\r\n* What problems were we trying to solve?\r\n 1. Positional type arguments are problematic because it locks you down.\r\n 2. Using a type parameter as a default for a temporary/local type.\r\n * `StrictEventEmitter`\r\n * \"Is this a real type!?\"\r\n 3. Specialized subclasses:\r\n\r\n ```ts\r\n class Box\u003cT> { x: T }\r\n class SpecialBox extends Box\u003cSpeical>\r\n\r\n // How do I specialize this further without making SpecialBox generic?\r\n class SpecialSpecialBox extends SpecialBox {\r\n }\r\n ```\r\n* At a high level, we want to be able to place types within types.\r\n\r\n ```ts\r\n declare class BoxObserver\u003cT> {\r\n type Boxified = { value: T };\r\n get(): Boxified;\r\n }\r\n let x: BoxObserver\u003cnumber, \r\n ```\r\n * Hold up though, that means in this class you can't write the following, since you don't know if `Boxified` will be further specialized.\r\n\r\n ```ts\r\n let x: T = this.get().value\r\n ```\r\n* Feels strange that these can appear in the type parameter list.\r\n* One of the core differences is that we also don't do inference on these types.\r\n* Also, these must be associated with the instance.\r\n * They must be, because they close over the instance type parameters.\r\n* If changing the type in the subtype changes the behavior in the supertype, then it must be a type variable.\r\n* But there are merits to just having this as an alias.\r\n * Could imagine\r\n\r\n ```ts\r\n declare class Foo\u003cT> with Boxified = { value: T } {\r\n get(): Boxified;\r\n }\r\n ```\r\n* Also, feels strange that there is some mixing of type parameters and aliases:\r\n\r\n ```ts\r\n type Foo\u003cT> =\r\n type X = Foo\u003cT>[] in {\r\n // ...\r\n };\r\n ```","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2018-09-06T22:52:18Z","url":"https://github.com/microsoft/TypeScript/issues/26952"}
| 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:aa1abf86-165c-ffb4-ae43-a64bee164720 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E320:215B92:2DAB983:3CD73E2:6B01D538 |
| html-safe-nonce | 4984e55efefd04b780599b9f31ee892bd27b10304c0e312b85840b4b94832b37 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzIwOjIxNUI5MjoyREFCOTgzOjNDRDczRTI6NkIwMUQ1MzgiLCJ2aXNpdG9yX2lkIjoiODcyNDY0MTM0Njc3MTYwNDc5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 13e291bd283d82f57bdc4121917e8086e36e7f9408e1b0fbfbe8cdb928c89a65 |
| hovercard-subject-tag | issue:357857032 |
| 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/26952/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b4b42c4d55a73f7641c76eebe87ff26b684daedec6904f4d263f9a3906c7287f/microsoft/TypeScript/issues/26952 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b4b42c4d55a73f7641c76eebe87ff26b684daedec6904f4d263f9a3906c7287f/microsoft/TypeScript/issues/26952 |
| og:image:alt | Call-site inference for implicit anys This is a demo presentation [[Opens up minimatch]] "This is the codebase you open up to make yourself feel good about JavaScript" Looking at the charSet declar... |
| 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 | 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