Repository navigation
TC39 proposal - Error.cause property #45167
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptES NextNew featurers for ECMAScript (a.k.a. ESNext)New featurers for ECMAScript (a.k.a. ESNext)Help WantedYou can do thisYou can do this
Milestone
Description
Activity
- addedBugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
on Jul 23, 2021 - addedES NextNew featurers for ECMAScript (a.k.a. ESNext)New featurers for ECMAScript (a.k.a. ESNext)
on Jul 26, 2021 johanneswuerbach commented
on Sep 7, 2021 More actionsError.causeis also available in Node 16.9.0 now 🎉Reacted by Toni Villena, Lukas Elmer and Sebastian MaltonReacted by Toni Villena, Matt Mahnke, Yvann Boucher, Simon Siefke, Lukas Elmer and Jan KowalleckBump
Reacted by Toni VillenaAlready Stage 4 - the feature is finalized!
Reacted by Toni Villena, Martin Andrej Johan Grönlund, Lukas Elmer and Roger PadillaThis seems to be partially implemented.
The constructor now accepts
ErrorOptionswith thecauseproperty - which is great.
However, this property is not declared in the Error object itself.With the full implementation this example should compile:
const error = new Error("derived", {cause: new Error("original")}); // OK console.log(error.cause); // Property 'cause' doesn't existReacted by Danilo Bargen, Nathan Shively-Sanders, Tom Brennan, Moaad Fattali, Lukas Elmer and Roger Padillasandersn commented
on Dec 16, 2021 MemberMore actionsThanks for pointing that out. I re-opened the bug.
Reacted by Lukas ElmerGoudekettingRM commented
on Feb 9, 2022 More actionsBump. Also ran into this. Fixed it local by redeclaring like this:
interface Error { name: string; message: string; cause?: any; stack?: string; } interface ErrorConstructor { new(message?: string, { cause }?: { cause: any }): Error; (message?: string): Error; readonly prototype: Error; } declare var Error: ErrorConstructor
I also had this issue for
causeandstack. Fixed it by redeclaring like this:interface ErrorInit { cause?: unknown; } declare type BaseError = Error; declare class Error implements BaseError { name: string; message: string; stack?: string; cause?: unknown; constructor(message?: string, init?: ErrorInit); // eslint-disable-next-line @typescript-eslint/ban-types -- Allow catch-all 'function' parameter type. static captureStackTrace(error: object, constructor?: Function): void; }
causewas added in #47020 and all definitions had shipped with 4.6.Reacted by Holger Jeromin, Martin Andrej Johan Grönlund, Matt Mahnke, Sung Jeon and mediscoMartinJohns commented
on Mar 19, 2022 ContributorMore actionsSimon Chan (@yume-chan) Although the type is inaccurate, as per #48098.
Reacted by Martin Andrej Johan Grönlund- added a commit that references this issue
on May 25, 2022 - locked as resolved and limited conversation to collaborators
on Oct 21, 2025
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptES NextNew featurers for ECMAScript (a.k.a. ESNext)New featurers for ECMAScript (a.k.a. ESNext)Help WantedYou can do thisYou can do this
lib.es2021d.ts Update Request - Error.cause property
Proposal (Stage 3)
https://github.com/tc39/proposal-error-cause
Already implemented in Chrome 93:
https://www.chromestatus.com/feature/5727099325251584
Sample Code