-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TC39 proposal - Error.cause property #45167
Comments
|
Bump |
Already Stage 4 - the feature is finalized! |
This seems to be partially implemented. The constructor now accepts With the full implementation this example should compile:
|
Thanks for pointing that out. I re-opened the bug. |
Bump. 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 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;
} |
|
@yume-chan Although the type is inaccurate, as per #48098. |
We need TypeScript 4.6+ to be able to construct Error objects with the cause property[1]. The property is useful to chain errors and, on the catching side, to see what error caused the error we just caught. I want to have this in place to implement [3] which satisfies a need we ourselves have[4]. tslib upgraded in lockstep because otherwise we get FAIL test/result.test.ts ● Test suite failed to run test/result.test.ts:121:29 - error TS2807: This syntax requires an imported helper named '__spreadArray' with 3 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. 121 const all4 = Result.all(...([] as Result<string, number>[])); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error [2] microsoft/TypeScript#45167 [3] vultix#34 [4] vultix#48
We need TypeScript 4.6+ to be able to construct Error objects with the cause property[1]. The property is useful to chain errors and, on the catching side, to see what error caused the error we just caught. I want to have this in place to implement [3] which satisfies a need we ourselves have[4]. tslib upgraded in lockstep because otherwise we get FAIL test/result.test.ts ● Test suite failed to run test/result.test.ts:121:29 - error TS2807: This syntax requires an imported helper named '__spreadArray' with 3 parameters, which is not compatible with the one in 'tslib'. Consider upgrading your version of 'tslib'. 121 const all4 = Result.all(...([] as Result<string, number>[])); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error [2] microsoft/TypeScript#45167 [3] vultix#34 [4] vultix#48
Adds the ability to configure the cause of an error when passing an error object to http exception. - https://nodejs.org/en/blog/release/v16.9.0/#error-cause - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error#rethrowing_an_error_with_a_cause - microsoft/TypeScript#45167
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
The text was updated successfully, but these errors were encountered: