microsoft / microsoft/TypeScript
TS2454 Variable is used before being assigned with strictNullChecks when variable is clearly assigned but can be undefined
Abierto
@RyanCavanaugh ya está trabajando en esto.
Desde el 30/8/2024.
Bug
Domain: check: Control Flow
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 Search Terms
Variable is used before being assigned TS2454 TS(2454) undefined strictNullChecks
🕗 Version & Regression Information
- This happens at least since version 3.7.5 (tested in the playground)
- This is the behavior in every version I tried, and I reviewed the FAQ
⏯ Playground Link
💻 Code
let test = undefined;
test = '' as string | undefined;
test?.length; // Variable 'test' is used before being assigned.
🙁 Actual behavior
Typescript throws an error complaining about test being used before being assigned but it's clearly assigned to undefined and then to ''.
Mine is a very simplicistic problem, but the same issues happens if a replace '' with a call to a function.
🙂 Expected behavior
Typescript should assign the type string | undefined to the variable test and let me use it.
Additional information about the issue
No response
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.