microsoft / microsoft/TypeScript
Identities should report an error
Abierto
@DanielRosenwasser ya está trabajando en esto.
Desde el 12/9/2023.
Experimentation Needed
Suggestion
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔍 Search Terms
Identity TS2367 impossible comparison
✅ Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Comparing identical literal (abc, 5, false) values in an "if" it should report it as redundant/impossible, similar to what TS2367 does.
📃 Motivating Example
function foo(): false {
return false;
}
function bar(): 'a' {
return '';
}
function t1(arg: unknown) {
if ( foo() !== true ) {
}
if ( foo() === true ) {
}
if ( foo() !== false ) {
}
if ( foo() === false ) {
}
if ( bar() !== 'b' ) {
}
if ( bar() === 'b' ) {
}
if ( bar() !== 'a' ) {
}
if ( bar() === 'a' ) {
}
}
💻 Use Cases
-
What do you want to use this for?
Get rid of legacy conditions/impossible code -
What shortcomings exist with current approaches?
No error reported -
What workarounds are you using in the meantime?
None, wasting time manually checking legacy code to see what can be removed.
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.