Not all of the Error constructors are displayed by TypeScript

My issue is straightforward: I am attempting to utilize the Error constructor that requires a message and an options object. Despite setting my tsconfig.json file to have

"target": "es2020"
, the Intellisense in VS Code only displays one constructor for Error (the one that just needs a message). Additionally, when I try to view the definition, the file that pops up is named lib.es5.d.ts.

Upon compilation, I receive the following error message:

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

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

Where am I going wrong here? Please advise if more clarification is needed.

Answer №1

It appears that the implementation of error cause was not completed in 2020. Upgrading to ESNext or a similar version may resolve this issue.

The 2021 update still lists it as a draft:

This suggests that it was officially introduced in es2022.

Answer №2

In ES2020, the options parameter for the Error constructor was not available. This feature was actually introduced in ES2022 (you can confirm its absence from ES2021). Consequently, TypeScript has included this in its declarations for ES2022 and beyond. To access this functionality, make sure to set your --target to "es2022" or a newer version.

Check out the code on the playground: Playground link to code

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is the custom attribute event being triggered too soon?

My Unique Component Creation Journey I have meticulously crafted a custom component to enhance the navigation of my application. The core structure consists of an ul element, with each li item dynamically generated based on the contents of the router&apo ...

incapable of destructuring two objects simultaneously

Is there a way to map movies using columns as a property reference? For example: {movies.map(item => {columns.map(column => item.column.path)})} When I try this, the result is always undefined. The 'movies' array contains detailed inform ...

The functionality of Pumpify varies between Node 8 and Node 10 environments

It's interesting how in Node 8, errors emitted on a stream are followed by the end event, but in Node 10 it's the reverse. This observation is based on using the latest 2.0.1 version of pumpify. Take a look at the example below: 'use strict ...

Exploring scroll functionality with Webdriver.io v4

My code is designed to log into the beta version of mediawiki, navigate to the Preferences page, and attempt to click on a button located at the bottom of the page. In order to achieve this, I am utilizing the scroll() function because using only .click() ...

Issues have arisen due to server calls being affected by AngularJS routing

I have implemented AngularJS in a nodewebkit application. There are three main views: Home.html Conversation.html Login.html Upon login, the following code is executed: $state.go('home.main'); which triggers the following state c ...

I'm so confused about the operation of each method in this context

I am experimenting with a simple process involving setTimeout function. My goal is to make the letters of a name appear individually and gradually at different times. For example, if the name is NAZ, I want the letters to appear in this order: first N, the ...

Is there a way to selectively add elements to the Promise.all() array based on certain conditions?

Here is the code snippet that I have written: I am aware that using the 'await' keyword inside a for-loop is not recommended. const booksNotBackedUp: number[] = []; for (let i = 0; i < usersBooks.length; i += 1) { const files = await ...

Pausing or buffering an RxJS 6 observable when the page is inactive

Currently, I am dealing with a stream of letters that need to be arranged in the correct order to form a word. However, an issue arises when the user switches tabs, minimizes the browser, or switches applications - the behavior mimics using setTimeout(), r ...

Coordinating multiple API requests for optimal performance

I have a task where I need to retrieve data from two different API endpoints. Once both sets of data are fetched, I need to compare the information obtained from each source. I am familiar with fetching data from a single API endpoint and using a callback ...

Guide on linking a trust policy to an IAM role through CDK

{ "Version": "2008-10-17", "Statement": [ { "Sid": "", "Effect": "Allow", "Principal": { "AWS": [ ...

Tips for utilizing jQuery ajax to invoke a PHP function

I have a file named myfunctions.php where I keep a collection of functions, such as function submitForm(){ //save form data } function anotherFunction(){ //perform a task } // More functions ... and the jQuery script, $.ajax({ url: "myfunction ...

Tips for automatically assigning a default value in a material select within an Angular application

Currently, I have an Angular screen that displays data from a database using a Java REST API. There is a field called esValido which only contains values of 1 and 0 as shown in the initial image. https://i.sstatic.net/R4WCc.png My goal is to implement a ...

Issues with Sound Not Playing When Button is Clicked in Python Flask

My goal is to trigger an audio sound when the Delete button is clicked. I've created an external JavaScript file and successfully linked it with Flask. index.html <a href="/delete/{{todoitem.item_id}}" class="btn btn-danger" onclick="playDelSound ...

Harnessing JavaScript templates within PHPHow to integrate JavaScript templates

I am currently working on a PHP document where I incorporate 'chapters' (jQuery tabs) in two different ways: Whenever a new chapter is generated, it gets added to the list as well as to the database using JavaScript and Ajax. I have already i ...

What is the iPad version of the onmousemove event?

I am currently facing an issue with a website on my iPad. Everything seems to be in order except for the onmousemove method. I am looking for a way to have onmousemove activated when the user swipes their finger across the screen. ...

Is it better to utilize AngularJS $http service for making requests, or should I opt for jQuery AJAX if available

When working on my project, I rely on the angularjs framework and always enjoy utilizing the $http service for ajax calls. However, I have come across situations in the project where the UI is not directly impacted by the ajax call and angularjs bindings a ...

Discover the power of positioning data labels in c3js!

Is there a way to adjust the position of labels above the data in a c3 bar chart? The official documentation explains how to modify the positions of labels on the x and y measurement axes by manipulating integers for y and x, but I couldn't find any i ...

A guide on implementing directives in Angular 2

I am trying to load my navbar.html in my app.component.html by using directives and following the method below: Here is my navbar html: <p>Hi, I am a pen</p> This is my navbar.ts: import {Component, Directive, OnInit} from '@angular/c ...

Discovering items within an array using Vue.js or JavaScript

I have an array of elements in Vue.js where I need to manipulate some data. For example, I have a select dropdown that displays company information with corresponding tags. These tags are at one sub level and are combined into one before being stored in th ...

IE is failing to trigger jAlert function

When I validate a text box by pressing the enter key on my keyboard, the validation works fine but the JAlert doesn't show up. However, when I call the same function on a button click, the alert shows in IE. I am quite confused by this behavior and wo ...