microsoft / microsoft/TypeScript
`InstanceType` and constructor return type inference doesn’t work for built‑in subtypes of `ErrorConstructor`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
### 🔎 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 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**.
### ⏯ Playground Link
https://www.typescriptlang.org/dev/bug-workbench/?#code/CYUwxgNghgTiAEkoGdnwMIFdkBcD2AtgKIwx4zwgAeOIAdsGiWRQN4BQAvu+zgJ4AHBADkiARngBeeAEk6uKHTAgAKoJAAeIgDcoEZuXR55OGJjD4YAPgDc7APT34z+AD0A-D35D4ogExSsiaKympCGgBKigDmIAYwRiZmFuS2Dk4uHl7qvkQAzIFyCkqq6pEgAGYgcCXxibjJlmmOLm6evDmiACyFwSVhmgDKfHQ4UFR1xg3mTXYtme3eIkQArL3FoWUDk0kzqXMZzlkdPqIAbOtj-WUAqhEyO9Mp1getx0sYRJchpeFLeBUMNh8MRSPt0m9PEA
### 💻 Code
```ts repro
declare class CustomError extends Error {
}
type NE1 = InstanceType;
// ^?
type NE2 = InstanceType;
// ^?
type NE3 = InstanceType;
// ^?
type NE4 = InstanceType;
// ^?
type NE5 = InstanceType;
// ^?
type NE6 = InstanceType;
// ^?
type CE = InstanceType;
// ^?
```
[Workbench Repro](https://www.typescriptlang.org/dev/bug-workbench/?#code/CYUwxgNghgTiAEkoGdnwMIFdkBcD2AtgKIwx4zwgAeOIAdsGiWRQN4BQAvu+zgJ4AHBADkiARngBeeAEk6uKHTAgAKoJAAeIgDcoEZuXR55OGJjD4YAPgDc7APT34z+AD0A-D35D4ogExSsiaKympCGgBKigDmIAYwRiZmFuS2Dk4uHl7qvkQAzIFyCkqq6pEgAGYgcCXxibjJlmmOLm6evDmiACyFwSVhmgDKfHQ4UFR1xg3mTXYtme3eIkQArL3FoWUDk0kzqXMZzlkdPqIAbOtj-WUAqhEyO9Mp1getx0sYRJchpeFLeBUMNh8MRSPt0m9PEA)
### 🙁 Actual behavior
Type query results:
```ts
type NE1 = Error
type NE2 = Error
type NE3 = Error
type NE4 = Error
type NE5 = Error
type NE6 = Error
type CE = CustomError
```
### 🙂 Expected behavior
Type query results:
```ts
type NE1 = EvalError
type NE2 = RangeError
type NE3 = ReferenceError
type NE4 = SyntaxError
type NE5 = TypeError
type NE6 = URIError
type CE = CustomError
```
### Additional information about the issue
Same happens with:
```ts repro
declare function newError(ctor: new (msg?: string) => E): E;
declare class CustomError extends Error {
}
let ne1 = newError(EvalError);
// ^?
let ne2 = newError(RangeError);
// ^?
let ne3 = newError(ReferenceError);
// ^?
let ne4 = newError(SyntaxError);
// ^?
let ne5 = newError(TypeError);
// ^?
let ne6 = newError(URIError);
// ^?
let ce = newError(CustomError);
// ^?
```
[Workbench Repro](https://www.typescriptlang.org/dev/bug-workbench/?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtX1RAHcBRGGHGAHhPhAA8MRVgBneMimAPgApNKALgLF4vALasA5gH5hrDDCyopASngBebh1XCSAbgBQoSLASnW7AMLIFOcZ0p1GzNh3JOA3oYC+hwxAgGCIAjJoipB4wvCQAblAQjjCqRgD0qfCZAHoy-oHBhABM4YSRXLwASlAqIEkphumZ8Dl5QSIAzCXESZUgiCBw6LVR9Y3ZuQFthAAsXWWUvADKAJ6oGFD0dWkZ460FIACscz0AKssADsNcozvNE-kiAGzHUbwAqhUAklsNty2TwTACA0ER6NjsDhG2yaLSAA)
### Related issues
- https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64628#pullrequestreview-1697561855
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal repro collegato in Playground e verifica come i tipi integrati ErrorConstructor interagiscono con InstanceType e la dichiarazione generica newError. Confronta i tipi inferiti con i risultati attesi per EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError e CustomError; il lavoro è completato quando le query sui tipi e le chiamate ai costruttori preservano ogni sottotipo specifico.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100