microsoft / microsoft/TypeScript
Compiler cannot handle promise.then(null | undefined)
Offen
@rbuckton arbeitet bereits daran.
Seit 17.6.2024.
Needs Investigation
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.