Title: Design Meeting Notes, 7/12/2024 · Issue #59362 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 7/12/2024 · Issue #59362 · microsoft/TypeScript
X Title: Design Meeting Notes, 7/12/2024 · Issue #59362 · microsoft/TypeScript
Description: Making Type Error Elaboration More Consistent #58859 Problem: you may get a different error elaboration in different locations depending on the order in which a program is checked. There are various reasons for this, with the class of di...
Open Graph Description: Making Type Error Elaboration More Consistent #58859 Problem: you may get a different error elaboration in different locations depending on the order in which a program is checked. There are variou...
X Description: Making Type Error Elaboration More Consistent #58859 Problem: you may get a different error elaboration in different locations depending on the order in which a program is checked. There are variou...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/59362
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 7/12/2024","articleBody":"# Making Type Error Elaboration More Consistent\n\nhttps://github.com/microsoft/TypeScript/pull/58859\n\n* Problem: you may get a different error elaboration in different locations depending on the order in which a program is checked.\n * There are various reasons for this, with the class of differences we're concerned about here, but we try to avoid reporting the full context if you've already seen it.\n* The main reason we're focusing on this is region-based diagnostics. If you first check statements in the middle of the file, it is weird to get a different level of error detail than top-down checking.\n* In this PR, every time we report a type error, we will now provide the full elaboration.\n\n# Deferred Parameters and Control Flow Analysis for Function Expression Arguments\n\nhttps://github.com/microsoft/TypeScript/pull/58729\n\n* Feel it is a valuable fix for a long-standing problem.\n* Core idea is to assume that callback function expressions are possibly called, and to factor that into the control flow analysis of variables used afterwards.\n* Means that in cases like\n\n ```ts\n let x: number | undefined;\n x = 42;\n someArray.forEach(() => { x = undefined; });\n x++; // Should be an error. Was not previously, is an error with this PR.\n ```\n\n now correctly fail to type-check.\n* To opt out, the idea is to introduce a `deferred` modifier; but there's a compatibility problem with all the tools in the ecosystem understanding that. Declaration files will need to introduce it and split between `typesVersions`, existing code may need an annotation even in `.ts` files.\n * PR also has support for `/** @deferred */` JSDoc comment that is understood in `.ts` files - not just `.js` files.\n* Also a question of a new parameter modifier being possibly in conflict with JavaScript.\n * We don't see one, but it might be worth reaching out to the committee to better understand concerns.\n* What's the relationship between a `deferred` callback and `await`?\n * It doesn't really factor in; we don't analyze deferred callbacks other than at the use-site.\n* How does declaration emit work for the JSDoc tag?\n * What you write is what you get.\n* What happens when a library is not upgraded to use `deferred`?\n * You can just use a type assertion to the expected type to opt out.\n * Alternatively, and maybe more preferred, is to write a function that takes a deferred callback and returns it.\n\n ```ts\n function deferred\u003cF extends (...args: never[]) => unknown>(deferred callback: F): F {\n return callback;\n }\n ```\n* We want to make sure that we're not missing anything. Will do the work to get Node.js and lib.d.ts/DOM libraries to have `deferred`.\n\n# \n\n```ts\ntype DataOrNull\u003cT> = {\n data: T | null;\n};\n\ndeclare function check(s: DataOrNull\u003cstring>): void;\n\ndeclare let foo: DataOrNull\u003cstring | null>;\ncheck(foo); // Error?\n```\n\n* We \"smartly\" infer that `T` is covariant (please disregard the soundness aspect here).\n * When we ask if `DataOrNull\u003cstring | null>` is assignable to `DataOrNull\u003cstring>`, we try to just ask \"is `string | null` assignable to `string`?\" and answer \"no\".\n* One idea: give people a new opt-out for variance calculation?\n\n ```ts\n type DataOrNull\u003cunmeasurable T> = {\n data: T | null;\n };\n ```\n\n* \"Unmeasurable\" is the concept we use internally to say \"this type parameter must always be checked with respect to the structure of the containing type\".\n* What do we name this?\n\n ```ts\n type DataOrNull\u003csus T> = {\n data: T | null;\n };\n ```\n* `structural`?\n* `linear`?\n* `inconsistent`?\n* `nonvariant`\n* Could we infer this better?\n * The pattern is common, and if we don't infer some variance in these scenarios, things are likely to get quite a bit slower.\n* Isn't a similar problem going to come up with libraries prioritizing correctness?\n * Unmeasurable variance is pretty infectious with type parameters. A type reference that takes a type variable for an unreliable type parameter makes the type variable also unreliable with respect to its containing type.\n* Could view this as \"unreliable\" - another internal view of type parameters, where they might have a variance, but uses the structural fallback.\n* What about this on the use-site?\n\n ```ts\n declare let foo: DataOrNull\u003cstructural string>;\n ```\n * Hard to think about what that means/explain to developers.\n* There are hacks to induce unreliable variance. @RyanCavanaugh will post this.","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2024-07-19T19:08:34Z","url":"https://github.com/microsoft/TypeScript/issues/59362"}
| 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:75c2c448-2bfc-b406-e817-8692ce340102 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6C4:1F68:417E0A:5C58C2:6B01BCB7 |
| html-safe-nonce | b423c058e7bbb78dc4b0f176489023d4c380a7059e54c0e5e0ef21e38eb87c02 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkM0OjFGNjg6NDE3RTBBOjVDNThDMjo2QjAxQkNCNyIsInZpc2l0b3JfaWQiOiI2NzYwNjkxODQ2NTU5NjUzNjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 81cf3d88b086dc1335868093176a530165dcd04fb2305fa509876ff067efd046 |
| hovercard-subject-tag | issue:2419662346 |
| 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/59362/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b6f89283bbc55c8bbbcf641f7e8a0b2474b0c47e7f00c7bf0cb23b37a479ee37/microsoft/TypeScript/issues/59362 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b6f89283bbc55c8bbbcf641f7e8a0b2474b0c47e7f00c7bf0cb23b37a479ee37/microsoft/TypeScript/issues/59362 |
| og:image:alt | Making Type Error Elaboration More Consistent #58859 Problem: you may get a different error elaboration in different locations depending on the order in which a program is checked. There are variou... |
| 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