microsoft / microsoft/TypeScript

useUnknownInCatchVariables would do much better to require ": unknown" rather than magically injecting it

Offen
#59,100 1 Kommentar 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: Error Messages Experience Enhancement Needs Proposal
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔎 Search Terms

useUnknownInCatchVariables

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about useUnknownInCatchVariables
⏯ Playground Link

No response

💻 Code

No response

🙁 Actual behavior

With useUnknownInCatchVariables :unknonw is magically injected after err (in catch (err))

try {
  console.log("in try")
}
catch (err) {
  console.log("in catch")
  console.log(err.message)
}

This results in a mysterious failure like so (from deno i.e. swc):

error: TS18046 [ERROR]: 'err' is of type 'unknown'.
    console.log(err.message)

The design of this option is very wrong, it's not worth the tiny saving of not having to type :unknown give how mysterious the above error is for a user who isn't aware of this option. It should have been designed to require this declaration rather than injecting it.

I realize this option can't be fixed at this point and it's probably not worth introducing a similar one with the better behavior. Perhaps as an alternative swc (and maybe other compilers) could be fixed to give an error that at least mentions useUnknownInCatchVariables.

🙂 Expected behavior

Something less mysterious :)

Additional information about the issue

None

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

Das Issue nennt die Option useUnknownInCatchVariables und die Diagnose TS18046. Beginne damit, zu überprüfen, wie diese Option die Diagnose in catch-Blöcken erzeugt. Als abgeschlossen gilt die Aufgabe, wenn das resultierende Verhalten oder der Fehler die Option klar erklärt und der erwartete Ansatz abgestimmt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

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