microsoft / microsoft/TypeScript
Compiler cannot handle promise.then(null | undefined)
Abierto
@rbuckton ya está trabajando en esto.
Desde el 17/6/2024.
Needs Investigation
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 Search Terms
"promise", "then", "null", "undefined", "nullable"
🕗 Version & Regression Information
- This changed between versions 3.33.3333 and 3.5.1
⏯ Playground Link
💻 Code
// Your code here
🙁 Actual behavior
// Let a promise that will resolve to 0;
const p = Promise.resolve(0);
// This should error but compiler says it is fine
function p3(): Promise<string> {
return p.then(null);
}
// I can basically claim that this function returns anything
function p4(): Promise<Window | Date | URL | { anything: "really" }> {
return p.then(null);
}
// This should also error but compiler says it is fine
function p5(): Promise<string> {
return p.then(undefined);
}
🙂 Expected behavior
// Let a promise that will resolve to 0;
const p = Promise.resolve(0);
// This should error with:
// Type 'number' is not assignable to type 'string'.
function p3(): Promise<string> {
return p.then(null);
}
// This should error with:
// Type 'number' is not assignable to type 'string'.
function p5(): Promise<string> {
return p.then(undefined);
}
Additional information about the issue
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.