microsoft / microsoft/TypeScript
TypeScript does not recognize unreachable code after a method returning never is called outside of its defining scope
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.89.1
- OS Version: All
To Reproduce:
class SimpleThrower {
public throwError(): never {
throw new Error('');
}
public doSomething(): string {
this.throwError(); // Directly call the never-returning function
return 'Success'; // TypeScript recognizes that this line is unreachable
}
}
() => {
const example = new SimpleThrower();
console.log(example.doSomething()); // This will throw an error
example.throwError(); // Throws an error and stops execution
console.log('foobar'); // TypeScript does not recognize that this line is unreachable
}
Expected behavior:
TypeScript should recognize that the line console.log('foobar'); is unreachable after example.throwError(); is called, similar to how it recognizes the unreachable code within the doSomething method.
Actual behavior:
TypeScript does not mark the line console.log('foobar'); as unreachable after the example.throwError(); call in the global scope or within a different function scope.
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.
Línea de trabajo
Comienza con el Playground Link proporcionado y compara cómo se reconoce el código inalcanzable dentro de doSomething después de this.throwError() con el comportamiento después de example.throwError() en la función externa. Rastrea el punto de entrada del análisis de flujo de control de TypeScript responsable de las llamadas a métodos que devuelven never; la tarea estará terminada cuando console.log('foobar') se marque como inalcanzable en este último caso sin que se produzca una regresión en el comportamiento existente de los métodos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 42/100