Title: `InstanceType` and constructor return type inference doesn’t work for built‑in subtypes of `ErrorConstructor` · Issue #61460 · microsoft/TypeScript · GitHub
Open Graph Title: `InstanceType` and constructor return type inference doesn’t work for built‑in subtypes of `ErrorConstructor` · Issue #61460 · microsoft/TypeScript
X Title: `InstanceType` and constructor return type inference doesn’t work for built‑in subtypes of `ErrorConstructor` · Issue #61460 · microsoft/TypeScript
Description: 🔎 Search Terms "ErrorConstructor" "InstanceType Error" "InstanceType ErrorConstructor" 🕗 Version & Regression Information This is the behaviour in every version I tried, and I reviewed the FAQ for entries about this. I was unable to test...
Open Graph Description: 🔎 Search Terms "ErrorConstructor" "InstanceType Error" "InstanceType ErrorConstructor" 🕗 Version & Regression Information This is the behaviour in every version I tried, and I reviewed the FAQ for ...
X Description: 🔎 Search Terms "ErrorConstructor" "InstanceType Error" "InstanceType ErrorConstructor" 🕗 Version & Regression Information This is the behaviour in every version I ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/61460
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`InstanceType` and constructor return type inference doesn’t work for built‑in subtypes of `ErrorConstructor`","articleBody":"### 🔎 Search Terms\n\n- \"ErrorConstructor\"\n- \"InstanceType Error\"\n- \"InstanceType ErrorConstructor\"\n\n### 🕗 Version & Regression Information\n\n- This is the behaviour in every version I tried, and I reviewed the FAQ for entries about this.\n- I was unable to test this on prior versions because `dtslint` only tests back to **TypeScript 5.0**, and the bug workbench failed to download versions older than **TypeScript 4.0**.\n\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/dev/bug-workbench/?#code/CYUwxgNghgTiAEkoGdnwMIFdkBcD2AtgKIwx4zwgAeOIAdsGiWRQN4BQAvu+zgJ4AHBADkiARngBeeAEk6uKHTAgAKoJAAeIgDcoEZuXR55OGJjD4YAPgDc7APT34z+AD0A-D35D4ogExSsiaKympCGgBKigDmIAYwRiZmFuS2Dk4uHl7qvkQAzIFyCkqq6pEgAGYgcCXxibjJlmmOLm6evDmiACyFwSVhmgDKfHQ4UFR1xg3mTXYtme3eIkQArL3FoWUDk0kzqXMZzlkdPqIAbOtj-WUAqhEyO9Mp1getx0sYRJchpeFLeBUMNh8MRSPt0m9PEA\n\n### 💻 Code\n\n```ts repro\ndeclare class CustomError extends Error {\n}\n\ntype NE1 = InstanceType\u003cEvalErrorConstructor>;\n// ^?\n\ntype NE2 = InstanceType\u003cRangeErrorConstructor>;\n// ^?\n\ntype NE3 = InstanceType\u003cReferenceErrorConstructor>;\n// ^?\n\ntype NE4 = InstanceType\u003cSyntaxErrorConstructor>;\n// ^?\n\ntype NE5 = InstanceType\u003cTypeErrorConstructor>;\n// ^?\n\ntype NE6 = InstanceType\u003cURIErrorConstructor>;\n// ^?\n\ntype CE = InstanceType\u003ctypeof CustomError>;\n// ^?\n```\n\n[Workbench Repro](https://www.typescriptlang.org/dev/bug-workbench/?#code/CYUwxgNghgTiAEkoGdnwMIFdkBcD2AtgKIwx4zwgAeOIAdsGiWRQN4BQAvu+zgJ4AHBADkiARngBeeAEk6uKHTAgAKoJAAeIgDcoEZuXR55OGJjD4YAPgDc7APT34z+AD0A-D35D4ogExSsiaKympCGgBKigDmIAYwRiZmFuS2Dk4uHl7qvkQAzIFyCkqq6pEgAGYgcCXxibjJlmmOLm6evDmiACyFwSVhmgDKfHQ4UFR1xg3mTXYtme3eIkQArL3FoWUDk0kzqXMZzlkdPqIAbOtj-WUAqhEyO9Mp1getx0sYRJchpeFLeBUMNh8MRSPt0m9PEA)\n\n### 🙁 Actual behavior\n\nType query results:\n```ts\ntype NE1 = Error\ntype NE2 = Error\ntype NE3 = Error\ntype NE4 = Error\ntype NE5 = Error\ntype NE6 = Error\ntype CE = CustomError\n```\n\n### 🙂 Expected behavior\n\nType query results:\n```ts\ntype NE1 = EvalError\ntype NE2 = RangeError\ntype NE3 = ReferenceError\ntype NE4 = SyntaxError\ntype NE5 = TypeError\ntype NE6 = URIError\ntype CE = CustomError\n```\n\n### Additional information about the issue\n\nSame happens with:\n```ts repro\ndeclare function newError\u003cE extends Error>(ctor: new (msg?: string) => E): E;\ndeclare class CustomError extends Error {\n}\n\nlet ne1 = newError(EvalError);\n// ^?\n\nlet ne2 = newError(RangeError);\n// ^?\n\nlet ne3 = newError(ReferenceError);\n// ^?\n\nlet ne4 = newError(SyntaxError);\n// ^?\n\nlet ne5 = newError(TypeError);\n// ^?\n\nlet ne6 = newError(URIError);\n// ^?\n\nlet ce = newError(CustomError);\n// ^?\n```\n\n[Workbench Repro](https://www.typescriptlang.org/dev/bug-workbench/?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtX1RAHcBRGGHGAHhPhAA8MRVgBneMimAPgApNKALgLF4vALasA5gH5hrDDCyopASngBebh1XCSAbgBQoSLASnW7AMLIFOcZ0p1GzNh3JOA3oYC+hwxAgGCIAjJoipB4wvCQAblAQjjCqRgD0qfCZAHoy-oHBhABM4YSRXLwASlAqIEkphumZ8Dl5QSIAzCXESZUgiCBw6LVR9Y3ZuQFthAAsXWWUvADKAJ6oGFD0dWkZ460FIACscz0AKssADsNcozvNE-kiAGzHUbwAqhUAklsNty2TwTACA0ER6NjsDhG2yaLSAA)\n\n### Related issues\n- https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64628#pullrequestreview-1697561855","author":{"url":"https://github.com/ExE-Boss","@type":"Person","name":"ExE-Boss"},"datePublished":"2025-03-21T13:01:16Z","url":"https://github.com/microsoft/TypeScript/issues/61460"}
| 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:2cf3dc6a-c046-6c42-992b-131c9b0116e3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DEEC:2FA59:C4F254:FDCC77:6B00EBD1 |
| html-safe-nonce | ea53e8eba5b802467e8df8f9dd21466419eb71e4e2fddadcc53b1c6d4fb18e25 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUVDOjJGQTU5OkM0RjI1NDpGRENDNzc6NkIwMEVCRDEiLCJ2aXNpdG9yX2lkIjoiODQ5NTc0ODQ0MzQ4NTAzOTU2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | efcd16e0d350d447623a395007be46d006cb36f87c19175f956df3045190d69f |
| hovercard-subject-tag | issue:2938340911 |
| 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/61460/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8bc57cbd4894f834564ced2a421d27b29f0ac062c9a6df1da774661fe3444e42/microsoft/TypeScript/issues/61460 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8bc57cbd4894f834564ced2a421d27b29f0ac062c9a6df1da774661fe3444e42/microsoft/TypeScript/issues/61460 |
| og:image:alt | 🔎 Search Terms "ErrorConstructor" "InstanceType Error" "InstanceType ErrorConstructor" 🕗 Version & Regression Information This is the behaviour in every version I tried, and I reviewed the FAQ for ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ExE-Boss |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width