Title: [TS 4.8] Deprecated factory methods aren't usable with originalNode.modifiers · Issue #49939 · microsoft/TypeScript · GitHub
Open Graph Title: [TS 4.8] Deprecated factory methods aren't usable with originalNode.modifiers · Issue #49939 · microsoft/TypeScript
X Title: [TS 4.8] Deprecated factory methods aren't usable with originalNode.modifiers · Issue #49939 · microsoft/TypeScript
Description: Bug Report Deprecated factory methods aren't usable with originalNode.modifiers. #49089 changed Node.prototype.modifiers from NodeArray
Open Graph Description: Bug Report Deprecated factory methods aren't usable with originalNode.modifiers. #49089 changed Node.prototype.modifiers from NodeArray
X Description: Bug Report Deprecated factory methods aren't usable with originalNode.modifiers. #49089 changed Node.prototype.modifiers from NodeArray<Modifier> to NodeArray<Modifier | Decorator>....
Opengraph URL: https://github.com/microsoft/TypeScript/issues/49939
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[TS 4.8] Deprecated factory methods aren't usable with originalNode.modifiers","articleBody":"# Bug Report\r\n\r\nDeprecated factory methods aren't usable with `originalNode.modifiers`.\r\n\r\n#49089 changed `Node.prototype.modifiers` from `NodeArray\u003cModifier>` to `NodeArray\u003cModifier | Decorator>`. It also changed factory functions to accept a single `NodeArray\u003cModifier | Decorator>` argument instead of separate modifiers and decorators arguments. The old factory functions are still available (they are deprecated now). But I imagine most usages of those old functions now result in a compile error for passing in `originalNode.modifiers`:\r\n\r\n> Argument of type 'NodeArray\u003cModifierLike>' is not assignable to parameter of type 'readonly Modifier[]'\r\n\r\n### 🔎 Search Terms\r\n\r\n4.8, modifiers, ModifiersArray, ModifierLike, decorators, Modifier, Decorator, factory\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.7.4 and 4.8-beta\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.7.4#code/JYWwDg9gTgLgBAKjgQwM5xugZlCI4BEMAnmAKaoDGUwYMBA3AFBNYCuAdpTMBBxlGQdUWaCADCAGzSoAImUqSAFNGABzAFwZUAOikz5i5IJ58AlHADeTOLbhQyMNlH6YdWZN2jEdbMABNkGDJ9VDkFaRNeDiUbO3jVNQAaOPjbRJ1-BWgg6FQUtLsMkAh-YCxgMih81LSMjmQQMgLCuAyScgAFY0bHKprWtpo1HQALKuAYZDUQ6TZUChbC4rIQACN+s2YAXyA)\r\n\r\nNote: Not sure how to reproduce this in the playground. `import from \"typescript\"` doesn't seem to import nightly typings in the playground.\r\n\r\n### 💻 Code\r\n\r\n```ts\r\nimport * as ts from \"typescript\";\r\n\r\nfunction transformClassDecl(orig: ts.ClassDeclaration) {\r\n return ts.factory.updateClassDeclaration(\r\n orig,\r\n orig.decorators,\r\n orig.modifiers,\r\n// ^^^^^^^^^^^^^^ TS2345: Argument of type 'NodeArray\u003cModifierLike>' is not assignable to parameter of type 'readonly Modifier[]'.\r\n orig.name,\r\n orig.typeParameters,\r\n orig.heritageClauses,\r\n orig.members);\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThis code snippet fails to compile with the error message inlined in the snippet.\r\n\r\n### 🙂 Expected behavior\r\n\r\nIdeally the deprecated `factory.updateXxx` functions would still be usable as before. This would make the upgrade to TypeScript 4.8 easier.\r\n\r\nI imagine most usages pass in `originalNode.modifiers` unchanged, unless they modify the modifiers. Picking Angular as a random example:\r\n\r\nhttps://github.com/angular/angular/blob/557cf7dc63fe768900f296252e1a96e6166b24df/packages/compiler-cli/src/ngtsc/transform/src/transform.ts#L210\r\n\r\n### Workarounds\r\n\r\nWe can change usages of factory functions to make code compatible with both TypeScript 4.7 and 4.8 by doing something like:\r\n\r\n```ts\r\nts.factory.updateClassDeclaration(\r\n orig,\r\n orig.decorators,\r\n orig.modifiers?.filter(ts.isModifier),\r\n ...\r\n)\r\n```","author":{"url":"https://github.com/frigus02","@type":"Person","name":"frigus02"},"datePublished":"2022-07-18T12:53:15Z","url":"https://github.com/microsoft/TypeScript/issues/49939"}
| 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:cf7555e4-fa8f-331b-daa6-22cf093da7d0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9AF0:3F8AB1:74B65F:98569D:6B00D487 |
| html-safe-nonce | 01d98aed4616fd594a6280b08ff545f44eb9d60fb4e87d300b649cd69773bf09 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUYwOjNGOEFCMTo3NEI2NUY6OTg1NjlEOjZCMDBENDg3IiwidmlzaXRvcl9pZCI6IjY3NTA1NTg4MDg1NDk5MzgzMTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 959720847d45097e44f6d5af16f1128fa56951a412f2848f2042fb987b0234c5 |
| hovercard-subject-tag | issue:1307915717 |
| 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/49939/issue_layout |
| twitter:image | https://opengraph.githubassets.com/65d82f13fec7576de603f1af0120ac7c70ff59bac20709d1b6dc3ecbee1297f6/microsoft/TypeScript/issues/49939 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/65d82f13fec7576de603f1af0120ac7c70ff59bac20709d1b6dc3ecbee1297f6/microsoft/TypeScript/issues/49939 |
| og:image:alt | Bug Report Deprecated factory methods aren't usable with originalNode.modifiers. #49089 changed Node.prototype.modifiers from NodeArray |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | frigus02 |
| hostname | github.com |
| expected-hostname | github.com |
| None | a481f62a1e04c9b9bdcb5628230682c66d59006f5b13b080f79cba84a176905b |
| 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 | 84c8c5cc25e2fb7f2308428458538436baecc6d2 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width