microsoft / microsoft/TypeScript
useUnknownInCatchVariables would do much better to require ": unknown" rather than magically injecting it
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
🔎 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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
L’issue mentionne l’option useUnknownInCatchVariables et le diagnostic TS18046. Commencez par examiner comment cette option produit le diagnostic dans les blocs catch. Le travail est considéré comme terminé lorsque le comportement ou l’erreur résultant explique clairement l’option et que l’approche attendue est convenue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100