Title: `Error.stack` type definition in lib.es5.d.ts is incorrect / `exactOptionalPropertyTypes` incompatible · Issue #45748 · microsoft/TypeScript · GitHub
Open Graph Title: `Error.stack` type definition in lib.es5.d.ts is incorrect / `exactOptionalPropertyTypes` incompatible · Issue #45748 · microsoft/TypeScript
X Title: `Error.stack` type definition in lib.es5.d.ts is incorrect / `exactOptionalPropertyTypes` incompatible · Issue #45748 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms Error.stack, exactOptionalPropertyTypes, ErrnoException 🕗 Version & Regression Information This is a type issue This changed in #8705 but it took until the 4.4 release for it to surface, thanks to exactOptionalP...
Open Graph Description: Bug Report 🔎 Search Terms Error.stack, exactOptionalPropertyTypes, ErrnoException 🕗 Version & Regression Information This is a type issue This changed in #8705 but it took until the 4.4 release for...
X Description: Bug Report 🔎 Search Terms Error.stack, exactOptionalPropertyTypes, ErrnoException 🕗 Version & Regression Information This is a type issue This changed in #8705 but it took until the 4.4 release...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/45748
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`Error.stack` type definition in lib.es5.d.ts is incorrect / `exactOptionalPropertyTypes` incompatible","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n Please fill in each section completely. Thank you!\r\n-->\r\n\r\n### 🔎 Search Terms\r\n\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n-->\r\n\r\nError.stack, exactOptionalPropertyTypes, ErrnoException\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n-->\r\n- This is a type issue\r\n- This changed in #8705 but it took until the `4.4` release for it to surface, thanks to `exactOptionalPropertyTypes` and it making `Error` incompatible with a corrected `Error`-subclass in `@types/node`: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55425\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about es5\r\n\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n-->\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?exactOptionalPropertyTypes=true#code/JYOwLgpgTgZghgYwgAgLIE8DCB7bAbAZTEQGtkBvAKGRuT1AgC5kBnMKUAc0oF9LLQkWIhQYAolCjYoyCAA9IIACYtkEqTKq1WxBCWYYc+IqQA+AV2UQYDJbyA) which is valid according to [the ECMAScript spec](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-error-constructor) and basically every other JS spec out there as `.stack` isn't standardized (as far as eg. [MDN knows](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack) at least)\r\n\r\nEdit: @ljharb has an ECMAScript Stage 1 proposal for [an Error Stacks spec](https://github.com/tc39/proposal-error-stacks).\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\ninterface MyCoolStack {\r\n line: string\r\n}\r\n\r\ninterface MyError extends Error {\r\n stack: MyCoolStack\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nGot error:\r\n\r\n```\r\nInterface 'MyError' incorrectly extends interface 'Error'.\r\n Types of property 'stack' are incompatible.\r\n Type 'MyCoolStack | undefined' is not assignable to type 'string'.\r\n Type 'undefined' is not assignable to type 'string'.\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\nOne of two:\r\n\r\n1. ~~Either that it passes completely...~~\r\n2. ...or at least that it complains the same as it does with [`exactOptionalPropertyTypes` turned off](https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgL):\r\n\r\n```\r\nInterface 'MyError' incorrectly extends interface 'Error'.\r\n Types of property 'stack' are incompatible.\r\n Type 'MyCoolStack | undefined' is not assignable to type 'string | undefined'.\r\n Type 'MyCoolStack' is not assignable to type 'string'.\r\n```\r\n\r\nEdit: The ECMAScript Stage 1 proposal for [an Error Stacks spec](https://github.com/tc39/proposal-error-stacks) defines that the `stack` should be [of type `string|undefined`](https://tc39.es/proposal-error-stacks/#sec-additional-built-in-properties), which makes the current type of `stack?:string` wrong and should be replaced with `stack?:string|undefined` if one agrees with that specs view of the current state of Error stacks.","author":{"url":"https://github.com/voxpelli","@type":"Person","name":"voxpelli"},"datePublished":"2021-09-06T19:51:36Z","url":"https://github.com/microsoft/TypeScript/issues/45748"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:52f21399-1503-2716-03e2-09362917b51a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA48:2A9AB5:C9D45A:104850D:6B063EF1 |
| html-safe-nonce | 5fa1c856fb1bd64154664601a81f943751bb6142c34fd37528af00903b99b29f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTQ4OjJBOUFCNTpDOUQ0NUE6MTA0ODUwRDo2QjA2M0VGMSIsInZpc2l0b3JfaWQiOiI2OTUyMTk0NDQwNjI3MTA5NjE3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9f30f172951e8e944eeb46e7eb34f27d66c28063fd681570da15aae86dd397cf |
| hovercard-subject-tag | issue:989407292 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/45748/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4a44fe6fcee31f01084f57968f93054a0e684f6d79d1c9fca9e683bb48d11d69/microsoft/TypeScript/issues/45748 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4a44fe6fcee31f01084f57968f93054a0e684f6d79d1c9fca9e683bb48d11d69/microsoft/TypeScript/issues/45748 |
| og:image:alt | Bug Report 🔎 Search Terms Error.stack, exactOptionalPropertyTypes, ErrnoException 🕗 Version & Regression Information This is a type issue This changed in #8705 but it took until the 4.4 release for... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | voxpelli |
| hostname | github.com |
| expected-hostname | github.com |
| None | dcf72c457c022486d23c3cbb0dd21aba537a87611ca9ddabd1799cf2eaa9b297 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0f38f5735226749ec5e08a8649dce4cb2613d9ad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width