I'm getting error TS2554 during build but not during dev on my Typescript project

49 views Asked by At

During dev there's no warnings or compile errors and eveything works fine but on npm run build I get the error TS2554 on a constructor saying Expected 0 - 1 arguments, but got 2.

The constructor has the following definition: ErrorConstructor

ErrorConstructor
(message?: string | undefined, options?: ErrorOptions | undefined) => Error (+1 overload)

ErrorOptions

interface ErrorOptions {
    cause?: unknown;
}

This error happens because I'm passing a cause through the ErrorOptions object and as mentioned above I get no error during dev or compile

throw Error('message', {cause: 'cause'})
1

There are 1 answers

1
Ivar Kallejärv On

Looking at your code I'd assume the code should be like this:

throw new Error('message', { cause: 'cause' });

Classes have to be initialized with the new keyword.