TypeScript does not show all of the Error constructors

Viewed 26

My problem is quite simple: I want to use the Error constructor that takes a message and an options object. Even though my tsconfig.json file states that "target": "es2020", VS Code's Intellisense only shows one constructor for Error (the one that only takes a message). Furthermore, when I navigate to the definition, the file that shows up is called lib.es5.d.ts.

If I try to compile, I get the following message:

src/FetchedConfigDataSource.ts:46:37 - error TS2554: Expected 0-1 arguments, but got 2.

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

What am I doing incorrectly here? Let me know if I should elaborate on anything.

2 Answers

I think error cause wasn't implemented in 2020, I think you need to upgrade to ESNext or similar.

It's still a draft in the 2021 update: https://tc39.es/proposal-error-cause/

This claims it was introduced in es2022.

Related