microsoft / microsoft/TypeScript

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

Abierto
#59,100 1 comentario 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Domain: Error Messages Experience Enhancement Needs Proposal
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

🔎 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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

El issue menciona la opción useUnknownInCatchVariables y el diagnóstico TS18046. Comienza revisando cómo esa opción produce el diagnóstico en los bloques catch. Se considera terminado cuando el comportamiento o error resultante explica claramente la opción y el enfoque esperado está acordado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.