Skip to content

[BUG] TS2370: A rest parameter must be of an array type. #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
monaxat opened this issue Apr 6, 2025 · 6 comments
Open

[BUG] TS2370: A rest parameter must be of an array type. #972

monaxat opened this issue Apr 6, 2025 · 6 comments

Comments

@monaxat
Copy link

monaxat commented Apr 6, 2025

Hi! 👋

Firstly, thanks for your work on this project! 🙂

I'm trying to use animejs v4.0.0 in my Angular project.
Has got this error:

X [ERROR] TS2370: A rest parameter must be of an array type. [plugin angular-compiler]

    node_modules/animejs/types/index.d.ts:253:24:
      253 │ ...ort let linear: (...args?: (string | number)[]) => EasingFunct...
          ╵                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
"@angular/core": "^19.0.0",
"typescript": "~5.8.2"
"animejs": "^4.0.0",

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "esModuleInterop": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2022",
    "module": "es2020",
    "lib": [
      "es2018",
      "es2020",
      "dom"
    ],
    "useDefineForClassFields": false
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": ["node"]
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

Here is the diff that solved my problem:

diff --git a/node_modules/animejs/types/index.d.ts b/node_modules/animejs/types/index.d.ts
index d00bc90..be37404 100644
--- a/node_modules/animejs/types/index.d.ts
+++ b/node_modules/animejs/types/index.d.ts
@@ -250,7 +250,7 @@ declare class Timeline extends Timer {
 declare function createTimeline(parameters?: TimelineParams): Timeline;
 type TimePosition = number | string | Function;
 declare namespace eases {
-    export let linear: (...args?: (string | number)[]) => EasingFunction;
+    export let linear: (...args: (string | number)[]) => EasingFunction;
     export let irregular: (length?: number, randomness?: number) => EasingFunction;
     export let steps: (steps?: number, fromStart?: boolean) => EasingFunction;
     export let cubicBezier: (mX1?: number, mY1?: number, mX2?: number, mY2?: number) => EasingFunction;

This issue body was partially generated by patch-package.

@juliangarnier
Copy link
Owner

Looking at your fix, it looks like it removes the ability to use the linear easing without any args?

Also the fix needs to be applied to the JSDoc type definition directly, not the index.d.ts file.

@monaxat
Copy link
Author

monaxat commented Apr 17, 2025

Looking at your fix, it looks like it removes the ability to use the linear easing without any args?

Also the fix needs to be applied to the JSDoc type definition directly, not the index.d.ts file.

Hi, thanks for take a look.
I agree this is not a proper way to fix problem, just a quick fix in the definition fine for make my project compiled.
There must be a right way how to make a rest parameter optional.

@juliangarnier juliangarnier changed the title TS2370: A rest parameter must be of an array type. [BUG] TS2370: A rest parameter must be of an array type. Apr 25, 2025
@Daverkex
Copy link

I have a similar issue in an Angular 19 with anime v4.0.2:

✘ [ERROR] TS2370: A rest parameter must be of an array type. [plugin angular-compiler]

    node_modules/.pnpm/[email protected]/node_modules/animejs/types/index.d.ts:253:24:
      253 │ ...ort let linear: (...args?: (string | number)[]) => EasingFunct...
          ╵                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


✘ [ERROR] TS1047: A rest parameter cannot be optional. [plugin angular-compiler]

    node_modules/.pnpm/[email protected]/node_modules/animejs/types/index.d.ts:253:31:
      253 │     export let linear: (...args?: (string | number)[]) => EasingF...
          ╵                                ^

@Daverkex
Copy link

The issue could be related to the Typescript configuration flag skipLibCheck. I had a similar issue with other lib and adding "skipLibCheck": true in tsconfig.json file solved the issue (not tested with anime).

This is a workaround, and anime should be compatible with the Typescript strict mode and the last Typescript spec.

@juliangarnier
Copy link
Owner

juliangarnier commented May 19, 2025

This is a workaround, and anime should be compatible with the Typescript strict mode and the last Typescript spec.

I agree, but does it means the linear easing function cannot have optional parameters?

-    export let linear: (...args?: (string | number)[]) => EasingFunction;
+    export let linear: (...args: (string | number)[]) => EasingFunction;

This is not a proper solution since args should be optional.

I'm open to suggestion here.

Thanks!

@juliangarnier juliangarnier mentioned this issue May 19, 2025
@Daverkex
Copy link

I agree with you. I'm not a expert of Typescript specification and I don't know why the Typescript team or spec changed it and what are the right implementation or alternative.

Please don't take my last comment as a pushing or anger. I only try to explain the issue isn't solved skipping the strictness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants