PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 3, 2022

[FIXED] How can I declare global Error type in typescript NodeJs Architect project?

 November 03, 2022     architect, error-handling, lambda, node.js, typescript     No comments   

Issue

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.


Solution

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"] }


Answered By - Tobias S.
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing