Title: Design Meeting Notes, 7/22/2022 · Issue #50008 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 7/22/2022 · Issue #50008 · microsoft/TypeScript
X Title: Design Meeting Notes, 7/22/2022 · Issue #50008 · microsoft/TypeScript
Description: Inference Change Between Unions of undefined #49938 Lots of examples Here's a minimal break. type B = { foo: string, }; type D = { foo: string, bar: number }; declare function equals
Open Graph Description: Inference Change Between Unions of undefined #49938 Lots of examples Here's a minimal break. type B = { foo: string, }; type D = { foo: string, bar: number }; declare function equals
X Description: Inference Change Between Unions of undefined #49938 Lots of examples Here's a minimal break. type B = { foo: string, }; type D = { foo: string, bar: number }; declare function equals<T>(a...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/50008
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 7/22/2022","articleBody":"# Inference Change Between Unions of `undefined`\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/49938\r\n\r\n[Lots of examples](https://www.staging-typescript.org/play?ts=4.8.0-pr-49981-17#code/GYVwdgxgLglg9mABAUwI4gIYBsA8AVAPgAoMAuRPAGkQCNy8BKRAb0QF8AoDrZKRAN0QBeRGBBYsAQgDcXAPRzEAeRoArZNERQAngAdkAZ0QB3GFAAWiCHAC2NhLQwHkWvYa479iAELCWiYDg4cgMoACcYMABzdg5PFwARP1ZA4MRQiOjpRzDyMRsaZDDYjjRMLCJBJx9qKqNwABNkYEjkBsQAH0QEhg4FRAA9AH5S9GxKxGrG5tb2roTayaNvXv7hrjLsHGmWsDbOn2I6moElxB3Zg56+xXXN3Au9ucOJqbAm3f35xeqVm8GRqNyq9lj96u8Zk9VrcRvcQecIZ8GmCfNCARsxhVjt4Udc1rDMfCFqdfmj1kDxtiUb4uo82mSCcDsQc6ciScsGRwgA)\r\n\r\nHere's a minimal break.\r\n\r\n```ts\r\ntype B = { foo: string, };\r\ntype D = { foo: string, bar: number };\r\n\r\ndeclare function equals\u003cT>(a: T, b: T): boolean;\r\n\r\nfunction f(b: B, d: D | undefined) {\r\n // Used to work, now infers `B` and fails.\r\n if (equals(b, d)) {\r\n\r\n }\r\n}\r\n```\r\n\r\n[Playground link](https://www.typescriptlang.org/play?ts=4.8.0-beta#code/C4TwDgpgBAQlC8UDeUBmB7dAuKBnYATgJYB2A5gDRQC+A3AFCiRQAiCyamO+x5VARgEMCOEgFcAtvwgEaDegBMIAYwA2w6KjEllwIuhJQIARzGDVuADwAVAHwAKQTmsDnAShz9MqiIJLytHT0DNHt+HBgqBRw2AB8obSVUUggFN2R6KCyoAHocqABVXFSoYHQoAHd0AgBrKhJ0CqhSVBlcKAADGA6oPwU0QSILADpM7KJUKHsTMwswqLd0pHoxrOp6aiA)\r\n\r\n* Bloomberg uncovered this from TS 4.8 Beta.\r\n* Why did this used to work?\r\n * We would get all the candidates, toss out the `undefined`, try to find the common super type, and re-add `undefined`.\r\n * Recent PR changed this (#49119), but https://github.com/microsoft/TypeScript/pull/49981 re-adds some of it.\r\n* Seems like we've found a middle-ground.\r\n* Didn't #49119 have\r\n * But the check for falsy flags went away (`getFalsyFlagsOfTypes` is a recursive fetch of flags)\r\n* Is this a desirable fix? Seems like a heuristic.\r\n * You can keep going and find use-cases where it becomes more and more arguable that you want to let things work.\r\n * Regardless, need to fix before 4.8.\r\n\r\n# Narrowing Changes Against Top-ish Types\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/49988\r\n\r\n* The `isMap` type predicate now narrows values to a `Map\u003c...> | ReadonlyMap\u003c...>` instead of `Map\u003c...>` if that's what you already had.\r\n* Introduced by https://github.com/microsoft/TypeScript/pull/49625\r\n* Start with this example.\r\n\r\n ```ts\r\n type Falsy = false | 0 | 0n | '' | null | undefined;\r\n\r\n declare function isFalsy(value: unknown): value is Falsy;\r\n\r\n function fx1(x: string | number | undefined) {\r\n if (isFalsy(x)) {\r\n x; // \"\" | 0 | undefined, previously undefined\r\n }\r\n }\r\n ```\r\n* But people depend on the old behavior.\r\n* This is now different\r\n ```ts\r\n declare function isMap\u003cT>(object: T | {}): object is T extends ReadonlyMap\u003cany, any> ? (unknown extends T ? never : ReadonlyMap\u003cany, any>) : Map\u003cunknown, unknown>;\r\n declare const romor: ReadonlyMap\u003cany, any> | Record\u003cany, any>\r\n if (isMap(romor)) {\r\n romor; // Previously `ReadonlyMap\u003cany, any>`, now `ReadonlyMap\u003cany, any> | Map\u003cany, any>`\r\n }\r\n ```\r\n* But `ReadonlyMap\u003c...> | Map\u003c...>` just provides all the same methods as `ReadonlyMap\u003c...>`.\r\n * Are they sufficiently identical between their methods?\r\n * Often these signatures are not, which makes them effectively uncallable.\r\n * We think yes.\r\n* [The `isObject` case is worse](https://github.com/microsoft/TypeScript/issues/49988#issuecomment-1192744372).\r\n * Previous behavior was weird! ([see playground](https://www.typescriptlang.org/play?ts=4.7.4#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXywGcB5AIwCtwMAKANygmRAC540BrVHAd1QEpW9RgiLwASuBwxgAHkIYYWVAHMANG1SceqAHwBuAFAGU6bHiQBGajgqsA3gF8+8OwfgFE8akTKVM1ij5nV3d3AHow+AB1KXZCdRtyAkJ4VFgYHhBgeAwccUlpOQUlNQ0tXh03UMSAbQAieWRERDqAXSqHA07jNExcfEQAJgDyewd4AB8NUEQlLOCqrE9vEgoqEaCXKvDIgBEsYFQAcgx4blj4ROTU9Mzs3PywKVl5RRV1Di4K7cuKesbmm0Ol0gA))\r\n\r\n ```ts\r\n declare function isObject(value: unknown): value is Record\u003cstring, unknown>;\r\n\r\n function f1(obj: {}) {\r\n if (isObject(obj)) {\r\n // Worked, obj is narrowed to Record\u003cstring, unknown>\r\n obj[\"stuff\"]\r\n }\r\n }\r\n\r\n function f2(obj: {} | undefined) {\r\n if (isObject(obj)) {\r\n // Doesn't work obj is not narrowed.\r\n obj[\"stuff\"]\r\n }\r\n }\r\n ```\r\n * Now neither example works. ([see playground](https://www.typescriptlang.org/play?ts=4.8.0-dev.20220722#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXywGcB5AIwCtwMAKANygmRAC540BrVHAd1QEpW9RgiLwASuBwxgAHkIYYWVAHMANG1SceqAHwBuAFAGU6bHiQBGajgqsA3gF8+8OwfgFE8akTKVM1ij5nV3d3AHow+AB1KXZCdRtyAkJ4VFgYHhBgeAwccUlpOQUlNQ0tXh03UMSAbQAieWRERDqAXSqHA07jNExcfEQAJgDyewd4AB8NUEQlLOCqrE9vEgoqEaCXKvDIgBEsYFQAcgx4blj4ROTU9Mzs3PywKVl5RRV1Di4K7cuKesbmm0Ol0gA))\r\n * Will need to think through these.\r\n* `WeakRef` example\r\n * Very incorrect. `T` is never witnessed, and `WeakRef` is supposed to be a proxy around `T` itself.","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2022-07-22T18:57:43Z","url":"https://github.com/microsoft/TypeScript/issues/50008"}
| 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:be9ae03d-6d27-f667-97c1-bc1d241cdad9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8024:63875:B7ACC9:F4B370:6B00F0E6 |
| html-safe-nonce | 44846cc31716f941dc19e4fa7f38a194d69c1b98cef482128aa5f0b100b22b65 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDI0OjYzODc1OkI3QUNDOTpGNEIzNzA6NkIwMEYwRTYiLCJ2aXNpdG9yX2lkIjoiNDM0MTM3OTcwNjUzMzI0NTE1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9dbc0813950ec5a6294cabf4a19d746e01cfbfd2b4eb40865c6c8ff67ca2da10 |
| hovercard-subject-tag | issue:1315324499 |
| 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/50008/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fb1b0ecd3cc4f468f1c27ca21a188886f90a464303b97dfbeb9d768fbf34034a/microsoft/TypeScript/issues/50008 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fb1b0ecd3cc4f468f1c27ca21a188886f90a464303b97dfbeb9d768fbf34034a/microsoft/TypeScript/issues/50008 |
| og:image:alt | Inference Change Between Unions of undefined #49938 Lots of examples Here's a minimal break. type B = { foo: string, }; type D = { foo: string, bar: number }; declare function equals |
| 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 | 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 |
Links:
Viewport: width=device-width