Title: Deprecated decorator factory APIs throw "Invalid arguments" runtime error · Issue #50259 · microsoft/TypeScript · GitHub
Open Graph Title: Deprecated decorator factory APIs throw "Invalid arguments" runtime error · Issue #50259 · microsoft/TypeScript
X Title: Deprecated decorator factory APIs throw "Invalid arguments" runtime error · Issue #50259 · microsoft/TypeScript
Description: Bug Report The following factory methods, that got deprecated in 4.8, throw an "Invalid arguments" type error at runtime, if the body parameter is not undefined: t.factory.createConstructorDeclaration(decorators, modifiers, parameters, b...
Open Graph Description: Bug Report The following factory methods, that got deprecated in 4.8, throw an "Invalid arguments" type error at runtime, if the body parameter is not undefined: t.factory.createConstructorDeclarat...
X Description: Bug Report The following factory methods, that got deprecated in 4.8, throw an "Invalid arguments" type error at runtime, if the body parameter is not undefined: t.factory.createConstruct...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/50259
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Deprecated decorator factory APIs throw \"Invalid arguments\" runtime error","articleBody":"# Bug Report\r\n\r\nThe following factory methods, that got deprecated in 4.8, throw an \"Invalid arguments\" type error at runtime, if the `body` parameter is not `undefined`:\r\n\r\n```\r\nt.factory.createConstructorDeclaration(decorators, modifiers, parameters, body);\r\nt.factory.updateConstructorDeclaration(ctor, decorators, modifiers, parameters, body);\r\n```\r\n\r\n### 🔎 Search Terms\r\n\r\nInvalid arguments, createConstructorDeclaration, updateConstructorDeclaration\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.7.4 and 4.8.0-dev.20220809\r\n\r\n### ⏯ Playground Link\r\n\r\nI don't think this can be reproduced in the playground.\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.8.0-beta#code/MYewdgzgLgBFEwLwwE4FMCOBXAlugFAORQCeADmhMCjmVIQJQDcAUC6JLAEYA2IwAayRwIAOgBmAQ2BQQKEqOppJUNACE+g-AG0AuszYB6QzADucgRHbhoMGXOHwJ02fMXoVaAMI2oKLPYoACJowDySKCo44PgsMDCGAFQwALYgACY44jhoKAiJJlhg6WjZYGjpADRxCclkEZIpaKp5MAUwetXxSTBcGSRtJrz8AtUGLMZmFlYctgD6WGTpnulergByaKYAgmQ4jmJSgQqLy6o+nP6BIWENUNFgsfGBXbWpGVk5re2BommZ2VyEFePXqkSaLXyJl+YMazSBIOSfXSAx+rlEyJIY1YExMUAAFigQKYEAAVchoACiKCJKHwACIAJJgABukh4OHSMAiAHMsE0wPB6QZZrA5oEAPI8dK7fbIJxHVwKJSeC7QK6uG7hSL3GI1HolUA6uRQmBFEplCqI94Ar6m82lHDlKr6uoNCFAwYdXTWzFe4aCbFGPGE4lkinU2kM5lsjlc3n8tCCiDC1iimALJYrNZyEJkdDAFayg7OY6iU6q3wa3OhbVRPXPVzWw1yFQmr2-FvGvLW-6fT1ouR-D6AvIAfgkOB4LXwThwEAAsiOvgxrbCPd9oej1-Ce67ev0O+jMdigA)\r\n\r\n### 💻 Code\r\n\r\nTo reproduce, you can:\r\n\r\n```sh\r\n$ mkdir repro\r\n$ npm init --yes\r\n$ npm install typescript@4.8.0-dev.20220809\r\n```\r\n\r\nAdd the following code in a file `index.js`. Then run `node index.js`.\r\n\r\n```ts\r\nconst ts = require('typescript');\r\n\r\nconst block = ts.factory.createBlock([]);\r\n\r\n// works\r\nconst ctor = ts.factory.createConstructorDeclaration(\r\n /* modifiers */ undefined,\r\n /* parameters */ [],\r\n /* body */ block,\r\n);\r\n\r\n// works\r\nconst _updatedCtorNewApi = ts.factory.updateConstructorDeclaration(\r\n ctor,\r\n /* modifiers */ ctor.modifiers,\r\n /* parameters */ ctor.parameters,\r\n /* body */ ctor.body,\r\n);\r\n\r\n// throws TypeError(\"Invalid arguments\");\r\nconst _ctorOldApi = ts.factory.createConstructorDeclaration(\r\n /* decorators */ undefined,\r\n /* modifiers */ undefined,\r\n /* parameters */ [],\r\n /* body */ block,\r\n);\r\n\r\n// throws TypeError(\"Invalid arguments\");\r\nconst _updatedCtorDeprecatedApi = ts.factory.updateConstructorDeclaration(\r\n ctor,\r\n /* decorators */ ctor.decorators,\r\n /* modifiers */ ctor.modifiers?.filter(ts.isModifier),\r\n /* parameters */ ctor.parameters,\r\n /* body */ ctor.body,\r\n);\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe deprecated functions createConstructorDeclaration and updateConstructorDeclaration throw an error at runtime. This makes it hard to write code, which works with both TypeScript 4.7 and 4.8.\r\n\r\n### 🙂 Expected behavior\r\n\r\nNo error 🙂 \r\n\r\n### 🕵️ Cause\r\n\r\nIf I understand the deprecation function overload logic correctly, the issue is here:\r\n\r\nhttps://github.com/microsoft/TypeScript/blob/3c3909b8d0a3d81cf320a84dac373eac19de3a7a/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts#L538\r\n\r\nhttps://github.com/microsoft/TypeScript/blob/3c3909b8d0a3d81cf320a84dac373eac19de3a7a/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts#L566\r\n\r\nThis should use `isBlock(body)` (without the negation).","author":{"url":"https://github.com/frigus02","@type":"Person","name":"frigus02"},"datePublished":"2022-08-10T14:00:16Z","url":"https://github.com/microsoft/TypeScript/issues/50259"}
| 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:c65b6867-80ca-c3ca-3879-06ac7851dd57 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CBBE:2BE220:5D7941:7ECC94:6B00D47E |
| html-safe-nonce | 00f76173bbaf2f03bb488761f4f94798941fbe64e4401cf3a05e29a940c45466 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkJFOjJCRTIyMDo1RDc5NDE6N0VDQzk0OjZCMDBENDdFIiwidmlzaXRvcl9pZCI6IjcxNjA1NzY2Mjg4MDY5NjQzNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0e729b8a3f6ac0e0aff8df11b1c1f2cd0f42401f771114371e4dad30ae66e2c8 |
| hovercard-subject-tag | issue:1334677301 |
| 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/50259/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8b3ce7d7296a49f077b7582e1e2186ce2c7a4bff53deed4fc5e7ecb63522d55b/microsoft/TypeScript/issues/50259 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8b3ce7d7296a49f077b7582e1e2186ce2c7a4bff53deed4fc5e7ecb63522d55b/microsoft/TypeScript/issues/50259 |
| og:image:alt | Bug Report The following factory methods, that got deprecated in 4.8, throw an "Invalid arguments" type error at runtime, if the body parameter is not undefined: t.factory.createConstructorDeclarat... |
| 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 | 85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5 |
| 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 | 4943239a6d2c591325dad6e5c313e1cafda877f6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width