microsoft / microsoft/TypeScript
Compiler cannot handle promise.then(null | undefined)
Aperta
@rbuckton ci sta già lavorando.
Dal 17/6/2024.
Needs Investigation
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.