microsoft / microsoft/TypeScript

`Error.stack` type definition in lib.es5.d.ts is incorrect / `exactOptionalPropertyTypes` incompatible

Offen
#45,748 7 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: lib.d.ts
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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 exactOptionalPropertyTypes and it making Error incompatible with a corrected Error-subclass in @types/node: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55425
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about es5
⏯ 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
interface MyCoolStack {
    line: string
}

interface MyError extends Error {
    stack: MyCoolStack
}
🙁 Actual behavior

Got error:

Interface 'MyError' incorrectly extends interface 'Error'.
  Types of property 'stack' are incompatible.
    Type 'MyCoolStack | undefined' is not assignable to type 'string'.
      Type 'undefined' is not assignable to type 'string'.
🙂 Expected behavior

One of two:

  1. Either that it passes completely...
  2. ...or at least that it complains the same as it does with exactOptionalPropertyTypes turned off:
Interface 'MyError' incorrectly extends interface 'Error'.
  Types of property 'stack' are incompatible.
    Type 'MyCoolStack | undefined' is not assignable to type 'string | undefined'.
      Type 'MyCoolStack' is not assignable to type 'string'.

Edit: The ECMAScript Stage 1 proposal for an Error Stacks spec defines that the stack should be of type string|undefined, 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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Untersuche die Error-Deklaration in lib.es5.d.ts und reproduziere die gemeldete Inkompatibilität mit dem verlinkten TypeScript Playground, wobei exactOptionalPropertyTypes aktiviert und deaktiviert ist. Vergleiche die resultierenden Diagnosen mit dem erwarteten Verhalten und dem verlinkten Vorschlag zu Error Stacks; abgeschlossen bedeutet, dass die Deklaration die vom Projekt gewählte Semantik für Error.stack widerspiegelt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.