microsoft / microsoft/TypeScript
useUnknownInCatchVariables would do much better to require ": unknown" rather than magically injecting it
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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
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
La issue indica l’opzione useUnknownInCatchVariables e la diagnostica TS18046. Inizia esaminando come tale opzione produce la diagnostica nei blocchi catch. Il lavoro è completato quando il comportamento o l’errore risultante spiega chiaramente l’opzione e l’approccio previsto è stato concordato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100