-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Error.stack
type definition in lib.es5.d.ts is incorrect / exactOptionalPropertyTypes
incompatible
#45748
Comments
Updated with a reference to @ljharb's and @erights' Error stacks ECMAScript proposal, which is currently in stage 1, but is probably the closest to a standard that is currently available and which also looks like a comprehensive research on the subject. |
In JavaScript, any type that forbids extra properties is incorrect, at least as far as most all builtins go, since the spec explicitly mandates that they all be extensible and that implementations be allowed to add extra properties.
I'm not clear on the actual issue here tho, since the playground link mandates an interface that is not nearly as defacto - and |
@ljharb Main issue is that, as defined now, if Here's a simplified playground: interface MyError extends Error {
stack: string|undefined
} With
And |
In what implementation would any error type have an undefined stack? |
Depends on how people have perceived it and how Error types are used in the community and engines, so I don’t know much more than it arising as an error in DefinitelyTyped/DefinitelyTyped#55425 I also note this in the stage 1 proposal:
|
That’s for the accessor, if you .call it on a non-error object, for back compat. Fair point tho, that the standard accessor can return undefined. |
Bumping this, as it's a major blocker to enabling |
Bug Report
🔎 Search Terms
Error.stack, exactOptionalPropertyTypes, ErrnoException
🕗 Version & Regression Information
4.4
release for it to surface, thanks toexactOptionalPropertyTypes
and it makingError
incompatible with a correctedError
-subclass in@types/node
: fix(node): error when exactOptionalPropertyTypes is enabled DefinitelyTyped/DefinitelyTyped#55425⏯ Playground Link
Playground link with relevant code which is valid according to the ECMAScript spec and basically every other JS spec out there as
.stack
isn't standardized (as far as eg. MDN knows at least)Edit: @ljharb has an ECMAScript Stage 1 proposal for an Error Stacks spec.
💻 Code
🙁 Actual behavior
Got error:
🙂 Expected behavior
One of two:
Either that it passes completely...exactOptionalPropertyTypes
turned off:Edit: The ECMAScript Stage 1 proposal for an Error Stacks spec defines that the
stack
should be of typestring|undefined
, which makes the current type ofstack?:string
wrong and should be replaced withstack?:string|undefined
if one agrees with that specs view of the current state of Error stacks.The text was updated successfully, but these errors were encountered: