0

Context

Hi, I have a NodeJs+Ts+Architect setup for building and deploying lambda functions. Architect uses typescript plugin to compile typescript. I am trying to use Error class to throw errors.

However, Typescript is picking up Error type from /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/lib.es5.d.ts.

In the image below, please note the constructor signature only accepts message field. And the error interface does not have an options object either. Please look at Browser Error Class or NodeJs Error Class to see the signatures.

enter image description here

Node Error has the following constructor signature and Error interface.

enter image description here

Problem

  • Getting TS Error for trying to use constructor signature of Node Error as Typescript is reading Error type from lib.es5.d.ts which accepts only 1 argument enter image description here

Possible Solutions which I know

  • Declare global Error type ( Need help here. Since Architect is compiling TS using its plugin, I am not able to declare and override Error interface )
  • Use your own Error class

I hope the question made sense. Would appreciate if there is a nicer way to solve this, but I am not getting ample discussions on Architect+Ts+NodeJs.

alchemist95
  • 759
  • 2
  • 9
  • 26

1 Answers1

1

The cause option was introduced in ES2022. You would need to use at least that version for your lib types.

Change the lib version in your tsconfig.json to:

"compilerOptions": { "lib": ["es2022"] }
Tobias S.
  • 21,159
  • 4
  • 27
  • 45
  • Thanks. This makes sense. However, I changed the lib version in tsconfig, I can also see lib.es2022.d.ts file in the same directory. but when I run tsc file.ts, it still errors out with the same error. Do I need to reference this config file as well if I am running tsc global? – alchemist95 Oct 31 '22 at 11:40
  • 1
    @alchemist95 - you could try to manually specify the `tsconfig.son` with `tsc --project ./your_path/tsconfig.json`. Maybe try also changing the target version to `es2022`? – Tobias S. Oct 31 '22 at 17:13