Title: Bloomberg feedback for 5.0 Beta · Issue #52670 · microsoft/TypeScript · GitHub
Open Graph Title: Bloomberg feedback for 5.0 Beta · Issue #52670 · microsoft/TypeScript
X Title: Bloomberg feedback for 5.0 Beta · Issue #52670 · microsoft/TypeScript
Description: By Michael Molisani (@molisani) & Titian Cernicova-Dragomir (@dragomirtitian) We are in the process of evaluating the impact of upgrading to TypeScript 5.0 on our codebase. Here are some preliminary findings. This is shaping up to be a m...
Open Graph Description: By Michael Molisani (@molisani) & Titian Cernicova-Dragomir (@dragomirtitian) We are in the process of evaluating the impact of upgrading to TypeScript 5.0 on our codebase. Here are some preliminar...
X Description: By Michael Molisani (@molisani) & Titian Cernicova-Dragomir (@dragomirtitian) We are in the process of evaluating the impact of upgrading to TypeScript 5.0 on our codebase. Here are some prelim...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/52670
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bloomberg feedback for 5.0 Beta","articleBody":"By @molisani & @dragomirtitian \r\n\r\nWe are in the process of evaluating the impact of upgrading to TypeScript 5.0 on our codebase. Here are some preliminary findings.\r\n\r\nThis is shaping up to be a medium impact release. The following table lists changes that affected our codebase, and where appropriate a link to a separate Issue:\r\n\r\n\r\n| # | Change | Affects | Release notes | Packages affected| Reported as |\r\n|---|-------------------------------------------------------|------------------|---------------|------------------|---------------------------------------------------------------------|\r\n| 1| Union with any does not reduce to any | Type Checking | Not Announced | ~6% | [#52568](https://github.com/microsoft/TypeScript/issues/52568) |\r\n| 2| No implicit coercions in relational operators | Type Checking | [Yes](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#forbidden-implicit-coercions-in-relational-operators) | ~2% | |\r\n| 3| Type inference for declared enum member assignment | Type Checking | Not Announced | ~2% | [#52531](https://github.com/microsoft/TypeScript/issues/52531) |\r\n| 4| Circular constraints don’t type check sometimes | Type Checking | Not Announced | ~1% | [#52570](https://github.com/microsoft/TypeScript/issues/52570) |\r\n| 5| `instanceof` narrows to `never` on else branch | Type Checking | Not Announced | 1 | [#52571](https://github.com/microsoft/TypeScript/issues/52571) |\r\n| 6| Nested callbacks are not contextually typed | Type Checking | Not Announced | 1 | [#52575](https://github.com/microsoft/TypeScript/issues/52575) |\r\n| 7| Declarations no longer include default type parameters| Declaration Emit | Not Announced | ~1% | |\r\n| 8| Misc type checking improvements | Type Checking | Not Announced | 2 | |\r\n\r\n\r\n## Union with `any` does not reduce to `any`\r\n\r\nGenerally `T | any` will reduce to any regardless of the origin of such a union. In TS 5.0 this is not the case for unions originating from a conditional type such as below. \r\n\r\n**Reported as ~~[#52568](https://github.com/microsoft/TypeScript/issues/52568)~~ (fixed)**\r\n\r\nFirst appeared in `5.0.0-dev.20221208`. A cursory look at merged PRs doesn’t reveal an immediate culprit. \r\n\r\n```ts\r\ntype Spec = any extends object ? any : string;\r\n\r\ntype WithSpec\u003cT extends number> = T\r\n\r\ntype R = WithSpec\u003cSpec>\r\n```\r\n[Playground Link](https://www.typescriptlang.org/play?ts=5.0.0-dev.20230201&ssl=5&ssc=24&pln=1&pc=1#code/C4TwDgpgBAypDGUC8UCGA7EUIA9gXQBMBnKAewCMArCeYKAfjUygC4pjgAnAS3QHMA3AFgAUGNCQoAdR7AAFnFoAeACrY8BElHQBXALYUIXAHzIoqsRPDQASudkKl8Zc5NA)\r\n\r\n## No implicit coercions in relational operators\r\n\r\nTypeScript now forbids implicit coercions when using relational operators as described [here](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#forbidden-implicit-coercions-in-relational-operators). We investigated a number of errors raised by this new check but none of them seem to be real runtime issues for us.\r\n\r\n## Circular constraints don’t type check sometimes\r\n\r\nThis is a very hard to reproduce issue. It only occurs in VS Code when you first open the file and can’t be reproduced using the CLI. Unfortunately it impacts our build tool which uses the compiler API. \r\n\r\n**Reported as [#52570](https://github.com/microsoft/TypeScript/issues/52570)**\r\n\r\nGive these files:\r\n\r\n```ts\r\n// types.ts\r\nexport type SelectorMap\u003cT extends Record\u003cstring, (...params: unknown[]) => unknown>> = {\r\n [key in keyof T]: T[key];\r\n};\r\n\r\n// index.ts\r\nexport declare const value2: {\r\n sliceSelectors: \u003cFuncMap extends import('./types').SelectorMap\u003cFuncMap>>(selectorsBySlice: FuncMap) => { [P in keyof FuncMap]: Parameters\u003cFuncMap[P]> };\r\n};\r\n```\r\n\r\nWe get these errors when we first open the types in VS Code. \r\n\r\n```\r\nType parameter 'FuncMap' has a circular constraint.\r\n\r\nType 'FuncMap[P]' does not satisfy the constraint '(...args: any) => any'.\r\n Type 'FuncMap[keyof FuncMap]' is not assignable to type '(...args: any) => any'.\r\n Type 'FuncMap[string] | FuncMap[number] | FuncMap[symbol]' is not assignable to type '(...args: any) => any'.\r\n Type 'FuncMap[string]' is not assignable to type '(...args: any) => any'.\r\n```\r\n\r\nAny subsequent editing will make the errors go away.\r\n\r\nGiven the very unstable nature of this bug, it might be a question of file ordering. Moving the SelectorMap to the same file and dropping the import makes the error go away.\r\n\r\nIn our case these types appear in generated declaration files.\r\n\r\nThe circular constraint which is present doesn’t seem to make much sense in our case, so we took the opportunity to clean up the types, so this is not blocking for us, but the behavior is still very strange.\r\n\r\n## `instanceof` narrows to `never` on else branch\r\n\r\nWhen testing with `instanceof` using a class that extends `Function` as the class, Typescript would previously not narrow the type on any branch. Now it narrows to never on the else branch. This causes some mixin code to break for us.\r\n\r\n\r\nFirst appeared in `5.0.0-dev.20221130`.\r\n\r\n**Reported as ~~[#52571](https://github.com/microsoft/TypeScript/issues/52571)~~ (fixed)**\r\n\r\n```ts\r\nclass PersonMixin extends Function {\r\n public [Symbol.hasInstance](o: any) {\r\n return typeof o === \"object\" && o !== null && o instanceof Person;\r\n } \r\n}\r\nconst cls = new PersonMixin();\r\n\r\n\r\nfunction test(o: Person | Car) {\r\n if (o instanceof cls) {\r\n console.log(\"Is Person\");\r\n (o as Person).work()\r\n }\r\n else {\r\n console.log(\"Is Car\")\r\n o.sayHi(); //o is never, was Person | Car\r\n }\r\n}\r\n```\r\n[Playground Link](https://www.typescriptlang.org/play?ts=5.0.0-dev.20230202#code/FDDGBsEMGdoAgAoFMBO0D2A7AsgSwB66ZxL4AuSmAJvAGICumoZuWcA3sHN3AA70AjcLlBwA2gGUAngFsB6cADoAFjACSmaGUhMkAXQAU6AFxwdUgJQcuPWyiRl6KYmSm8k6AGZx0cALwBcABE6AIAVkjMQXAAZDE+cACEgZj04OCx8b5EWjqgHt7IaFgA3DbcAL62wBVgWFpwEPB+cJhIAO6IqBg4BEQGFmVgULBdxcSctu3oKADWA6YAbui4VByN9QpIiuDoAOYGQdNzQVa1ttCQUgASuAtwy6vroJvg27sHQbencLW1EDB4ABhSAoawXK63e6PNbsDaaLY7faHADqXjgaM8Pz+IE8jGYrBcSC0RlMYx6cAAPnAQSgrJMeLhvEY4DltLp0U16eVbPCMG8kZ81PAij1TmVeTwWTByVgLIpjvMLDzzjwkOBoEhwZK+YiPodhTTQacebZ0IpLjc7oM4AB6W3ZeBtRaoFU1YAUEltTqiuUe4lkAzeo10oA)\r\n\r\n\r\n## Declarations no longer include default type parameters\r\n\r\nOn imported types with a type parameter that has a default, the default type for the type parameter is no longer included in the declaration emit (this is not the case if the type is in the same file):\r\n\r\n```ts\r\n// types.ts\r\nexport declare type Table\u003cS = string> = { value: S };\r\n \r\n// Emitted in both 4.9 and 5.0 as\r\n// export declare const o: Table\u003cstring>;\r\nexport const o = null! as Table\r\n```\r\n\r\n```ts\r\n// index.ts\r\nimport { Table } from \"./type\";\r\n\r\n\r\n// Emitted in 5.0 as\r\n// export declare const o: Table;\r\n// Emitted in 4.9 as\r\n// export declare const o: Table\u003cstring>;\r\nexport const o = null! as Table\r\n```\r\n\r\n\r\nThis is arguably a very good improvement to declaration emit as it makes declarations not depend on the default of the original type, allowing it to change without the need to rebuild all downstream declarations.\r\n\r\n## Nested callbacks are not contextually typed\r\nNested callback parameters are not contextually typed if the signature comes from an indexed type, indexed with a type parameter.\r\n\r\n**Reported as [#52575](https://github.com/microsoft/TypeScript/issues/52575)**\r\n\r\n```ts\r\nexport interface Event\u003cT> {\r\n callback: (response: T) => void;\r\n nested: {\r\n callback: (response: T) => void;\r\n }\r\n}\r\n\r\n\r\nexport type CustomEvents = {\r\n a: Event\u003cstring>\r\n b: Event\u003cnumber> // If only one candidate type exists it works\r\n};\r\n\r\n\r\ndeclare function emit\u003cT extends keyof CustomEvents>(type: T, data: CustomEvents[T]): void\r\n\r\n\r\nemit('a', {\r\n callback: (r) => {},\r\n nested: {\r\n callback: (response) => {\r\n\r\n\r\n },\r\n },\r\n});\r\n```\r\n[Playground Link](https://www.typescriptlang.org/play?ts=5.0.0-dev.20230102#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgUQDdgUAeAFQD44BvAKDkbm0wBtWAjHAawC44AFFGABnSEhHB+5AJRwAvNUIQEAEwDcDJklGpV-ekyPM2nHvyGjxk6XMVxlazUYC+dN3VCRYcGAE8wPABhAFcRGAgAWyISGBEFWi1GTH4YsnCoZABzSiS4DlTiMiQQyI40agB6SrgASXQ4CCRWP0adEyRVNUxUXwC8UARw+IR4AHdobhF3TTpVYGxWTGE4dBCkbBgEJrhgSNGKXZBUTvjuYD8IBtDwqLS4ygF-QOkAGjhVHpS4G4jooriAG1yABdGT8RyqOiefYwAQAckw8PehiYLHYXGwfEEUDs1BoLleeR04WA+kSxjRpkx2MsYiakjxiTyriJrPcMk0QA)\r\n\r\n## Misc type checking improvements\r\n\r\n### The following code now errors, as it should, where it did not in 4.9:\r\n\r\n```ts\r\nlet exports: { x?: unknown; foo?: unknown } = {};\r\nexports = exports.foo; // error in 5.0 not in 4.9\r\n```\r\n[Playground Link](https://www.typescriptlang.org/play?ts=4.9.4#code/DYUwLgBCAeAOD2AnMBnAXBA3haB+DArgHYDWR8A7kQNwQBm88+ExZlREAvhALxafUAsACgYCZCl5Q4SVADoG8IcKA)\r\n\r\n### Destructuring from unknown inside a catch error variable is now an error:\r\n\r\n```ts\r\ntry {\r\n} catch ({\r\n status, // error in 5.0 not in 4.9\r\n}: unknown) {\r\n}\r\n```\r\n[Playground Link](https://www.typescriptlang.org/play?ts=5.0.0-dev.20221207#code/C4JwngBA3gsAUAXwgYwIbGQCwgClnCQiAZ2HQFdiAaCAelogFMQQB7ECASwDsIBWAHQAGCN1bAuvACwCAnPAQAuCOW4BrMQHduASmgKgA)\r\n\r\n","author":{"url":"https://github.com/dragomirtitian","@type":"Person","name":"dragomirtitian"},"datePublished":"2023-02-08T10:46:21Z","url":"https://github.com/microsoft/TypeScript/issues/52670"}
| 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:c4182ec5-fc85-16ac-4db4-fdc9730b522d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9498:399E4B:28B4025:3607579:6B01AB25 |
| html-safe-nonce | a5ebbe1ecc01c3ba1f0abd40188b28875b83a7dec54ffb782dff55b0fded97ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDk4OjM5OUU0QjoyOEI0MDI1OjM2MDc1Nzk6NkIwMUFCMjUiLCJ2aXNpdG9yX2lkIjoiNzYxMDQzMTU1NDkyOTY2Njg1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f631a77db024d28f7059a8764e355aec67b40b5d9196730bdde9e1324d0a7065 |
| hovercard-subject-tag | issue:1575892269 |
| 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/52670/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bb32b239242eea1a3d587779c386f4c8d62038ec4849ed7cab373d057aabb7ad/microsoft/TypeScript/issues/52670 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bb32b239242eea1a3d587779c386f4c8d62038ec4849ed7cab373d057aabb7ad/microsoft/TypeScript/issues/52670 |
| og:image:alt | By Michael Molisani (@molisani) & Titian Cernicova-Dragomir (@dragomirtitian) We are in the process of evaluating the impact of upgrading to TypeScript 5.0 on our codebase. Here are some preliminar... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dragomirtitian |
| 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