Title: Design Meeting Notes, 2/14/2020 · Issue #36877 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 2/14/2020 · Issue #36877 · microsoft/TypeScript
X Title: Design Meeting Notes, 2/14/2020 · Issue #36877 · microsoft/TypeScript
Description: Touched-up edits from me on Ben Lichtman (@uniqueiniquity)'s notes Discriminated Narrowing with typeof #32399 Today we do checks to narrow types depending on specific checks on literal types But using typeof doesn't narrow in the same wa...
Open Graph Description: Touched-up edits from me on Ben Lichtman (@uniqueiniquity)'s notes Discriminated Narrowing with typeof #32399 Today we do checks to narrow types depending on specific checks on literal types But us...
X Description: Touched-up edits from me on Ben Lichtman (@uniqueiniquity)'s notes Discriminated Narrowing with typeof #32399 Today we do checks to narrow types depending on specific checks on literal types Bu...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/36877
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 2/14/2020","articleBody":"Touched-up edits from me on @uniqueiniquity's notes\r\n\r\n## Discriminated Narrowing with `typeof`\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/32399\r\n\r\n- Today we do checks to narrow types depending on specific checks on literal types\r\n- But using typeof doesn't narrow in the same way when checking against primitive types\r\n- in the checking process order, we check for discriminated properties very early\r\n- Brian's example would work easier than the original example\r\n- Once there is an object in a property, that makes it no longer possibly discriminating\r\n - null/undefined are different\r\n- two separate features:\r\n - discriminate inside of typeof test (make typeof apply discriminate narrowing)\r\n - this is the one azure sdk wants\r\n - discriminate when something _is_ an object (as opposed to _is not_ null or undefined)\r\n- We should do the former, probably not the latter\r\n\r\n## Non-null assertions `!` with Optional Chaining `?.`\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/36031\r\n\r\n- Revisiting issue from a month ago\r\n- The bang breaks the chain, thereby causing unexpected accesses on `undefined`\r\n- After exploring a solution, the problem is that `a?.b.c!` can still be undefined\r\n- Option A: Can we special case that example?\r\n- Option B: Can we say that the bang is part of a chain only when it's in the middle?\r\n- C# has similar struggles with this example\r\n- Our parsing strategy caused this issue - _technically_ postfix bang shouldn't be allowed to be mixed\r\n - let's keep it allowed, too awkward to disallow\r\n- why would you have a trailing bang?\r\n - defend against incorrect library types, so we do care\r\n- Option B is definitely preferred - seems straightforward and understandable\r\n- concern about breaking change if we do option B\r\n- Option C: we could require parens\r\n- How bad is this problem?\r\n - Unintuitive for users\r\n - It has 4 upvotes\r\n- Conclusion: Option B!\r\n- Do we want it for 3.8.2? No, wait for 3.9.\r\n\r\n## Can appending `.js` in Auto-Imports make sense?\r\n\r\nhttps://github.com/microsoft/TypeScript/pull/36725\r\n\r\n- An extension (e.g. `.js`) is required in Node ESM and Browser ESM for ESM imports\r\n- Add another option? Actually, we already have it...\r\n - `importModuleSpecifierEnding` for editor options\r\n- should it just be determined by emit? no, might be using a bundler\r\n- Do we need to support export maps to do this correctly?\r\n - as part of full Node ESM support, but not piecemeal \r\n- VS Code just wants the option\r\n- Also we've gotten requests for it to be an error to leave off the extension, but that's a separate issue\r\n- Now that browsers support import maps, classic resolution is not the best mode anymore, might need a third that supersedes these fixes\r\n- Should we give the option to VS Code now or say we'll get this done as part of future resolver work?\r\n - worried that customers don't use what this is for, but we should really just have it\r\n- Let's ship the auto-import option for 3.9, it's already there.\r\n\r\n## Making Impossible Intersections of Discriminated Unions Produce `never`\r\n\r\nhttps://github.com/microsoft/TypeScript/pull/36696\r\n\r\n- Our type rewriting rules often create types that don't make sense\r\n- Originally didn't resolve this because we thought it was expensive and would cause circularities\r\n- Now, once we're about resolve the members of the union, we reduce, instead of reducing up front\r\n- you can view this as detecting the intersection version of discriminants\r\n- note that if one has an explicitly designated never type, we allow this\r\n\r\n ```ts\r\n type A = { kind: 'a', foo: string};\r\n type B = { kind: 'b', foo: number};\r\n type C = { kind: 'c', foo: number };\r\n ```\r\n\r\n ```ts\r\n declare let x: A | (B & C);\r\n let a: A = x; // previously error, now the same\r\n ```\r\n\r\n- Originally motivated because we can't run the compiler with unions in our perf suites because of #31838 making types more inclusive caused Node's `parent` property to be massive\r\n- Now by reducing when the parent property is accessed, it greatly helped the problem\r\n- 10% speedup for material-ui, will help styled-components as well, and React's ref property\r\n- Key insight is that the only way to solve this problem is to not do it when constructing the intersection, but instead defer until a member is resolved\r\n- This is a breaking change: we will explore more members than we have before\r\n- We found two bugs in the current compiler, found bugs in DT\r\n- Not going to detect doubly nested discriminants at the outer level, so that won't break\r\n\r\n ```ts\r\n declare let xx: B & C;\r\n xx.foo // today you get number, with this change its an error\r\n ```\r\n\r\n- Willing to take the breaking change nature of this because we found errors and the perf benefits are a clear win\r\n","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2020-02-19T18:53:50Z","url":"https://github.com/microsoft/TypeScript/issues/36877"}
| 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:83a35a69-2074-32f1-c5aa-c745927a2dea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C6C:205334:5DCB55:843773:6B047588 |
| html-safe-nonce | 9e3516e6789b6724613b925e62bd3175f042b486ec4af0c2bad3011780f89fdc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzZDOjIwNTMzNDo1RENCNTU6ODQzNzczOjZCMDQ3NTg4IiwidmlzaXRvcl9pZCI6IjM0NDcyNzYzNjcxNTc0MjU1NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | eb9b3c512f3d8a5259fa0d0bc1fbadd15287598344dc6ca889c59890a66dfec9 |
| hovercard-subject-tag | issue:567772194 |
| 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/36877/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6b9e6f6f4754665382a3537c9a7f4d4598936c19ae809f2e0a15869ec8bab1a5/microsoft/TypeScript/issues/36877 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6b9e6f6f4754665382a3537c9a7f4d4598936c19ae809f2e0a15869ec8bab1a5/microsoft/TypeScript/issues/36877 |
| og:image:alt | Touched-up edits from me on Ben Lichtman (@uniqueiniquity)'s notes Discriminated Narrowing with typeof #32399 Today we do checks to narrow types depending on specific checks on literal types But us... |
| 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 | 9c099f1b85def81ca352464c276510dfef32deaf3c305404e65b8d270284a58b |
| 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 | cf73f57448d52b3a7b619195e182b33d3b3454ca |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width