microsoft / microsoft/TypeScript

Compiler cannot handle promise.then(null | undefined)

Ouverte
#58,619 8 commentaires 0 réactions 1 personne assignée Voir sur GitHub

@rbuckton y travaille déjà.

Depuis le 17/6/2024.

Needs Investigation
Langage dominant
Go
Étoiles
111k
Forks
14.4k
Merge moyen
1 j 19 h
PR mergées (30 j)
117

Description

🔎 Search Terms

"promise", "then", "null", "undefined", "nullable"

🕗 Version & Regression Information
  • This changed between versions 3.33.3333 and 3.5.1
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.4.5#code/PTAEBkFMBdQQ1ABwE4HsC2BLAzpU0ALOWAd0wBtzRlJtVyA3PaVUABgG4AoAY1QDtssRKAC8oAAposuAHQ06jSAAo2ASg6guXEKAAqBHKCN9kNHtAA0oPukQVIyY-wBmj7JOk5IAHn4BXdAAjRwA+Lhd-fgtMASQ2ZTVQAG8uUHTqGH9kfiRuAF8dMAMjIzhyOhtUM0gLa1t7ckdQJmRMF0xaTwxvP0CQ5FCq-mhkOAsIqJi4xABGRIAubplfAOCwlLSMmmhs3MQCov1DDzKK1lNzaCWGhydIV2qeLqke3B8hNv4AcyG+EbGFi0uj0AE9EHgAORrAaQ4wefioWBwbDYTDffhwIJNfCsaDgqGfTA-SGySbRaCxfYAJkWy16RJ+Q1SGUyuxyeS4hRBJ1A2AIqH85AAJqBHGgnEF-LBbk0nNg4KDTrAjB1+JBydN9gBmOmvFYfUbE36bVk7PZIWSEB7KAKUDRco4ASRscFyQRRmB45XIoJs5DgmHQ+CIsEIqqmlLi5pyHjdoPDP01Uf2ABY9V53gB1YnC1AkUAAH1AABFiHhiwBVABK4CLKXg-AThh+SwARDQfaC26B8sytukY-srQQbXbyA7ucVefzBSL4OcxWZqqApTKMI1mgqlcYVR41RrIhSqUgAKwZt6+RkmlnbLIcxAjm1RYWQA-CydAA

💻 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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.