[7.1 Regression] Unexpected behaviour change from Stronger Distributive Type checks
Les mainteneurs répondent en général sous 1 jour
Évaluation
Cette issue n'a pas encore été évaluée.
Description
🔎 Search Terms
7.1 regression, TS2345
🕗 Version & Regression Information
- This changed between versions 7.0.2 and 7.1.0-beta
⏯ Playground Link
💻 Code
export class C {
m1<T>(
item: T,
callback: T extends string
? (item: T) => void
: (item: T) => void
): void {
callback(item);
callback(item as T extends string ? T : T);
}
m2(
item: string,
callback?: (item: string) => void
): void;
m2<T>(
item: T,
callback: (item: T) => void
): void;
m2<T>(
item: T,
callback: T extends string
? ((item: T) => void) | undefined
: (item: T) => void
): void {
if (callback) {
callback(item);
callback(item as T extends string ? T : T);
}
}
}
🙁 Actual behavior
src/main.ts:8:18 - error TS2345: Argument of type 'T' is not assignable to parameter of type 'T'.
'T' is only assignable to the non-distributed 'T', but 'T' has been distributed here.
8 callback(item);
~~~~
src/main.ts:27:22 - error TS2345: Argument of type 'T' is not assignable to parameter of type 'T'.
'T' is only assignable to the non-distributed 'T', but 'T' has been distributed here.
27 callback(item);
🙂 Expected behavior
No Error.
Additional information about the issue
In case of m1, if tsc is aiming to strengthen Distributive Type checks, I would hope tsc can be smart enough to "undistribute" type whenever it hits some identical declarations on different branches. As for how to define identical, I suppose it may deserve further thinkings and discussions.
For m2, we have a common way of writing overload in typescript. The condition T extends string is there for determining if a method argument is optional or not. The (strengthened) disributive check that follows is kinda unintended & unwanted effect in this case. It would be weird to let the ? T : T trick to become a part of usual type overload maintenance.
I am treating the stronger checks as regression, since it actually brings undesired behaviour changes as presented above.
- Langage dominant
- Go
- Étoiles
- 112k
- Forks
- 15.4k
- Merge moyen
- 2 j 21 h
- PR mergées (30 j)
- 126
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoft/TypeScript
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file locationOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
microsoft/TypeScript#65087 ·
Les mainteneurs répondent en général sous 1 jour
-
API: `tsc.exe` opens a visible console window on Windows when the parent process has no consoleOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
microsoft/TypeScript#65083 ·
Les mainteneurs répondent en général sous 1 jour
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'Peut-être à nouveau libre Une pull request pour cette issue a été fermée sans être fusionnée. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
microsoft/TypeScript#64758 ·
Les mainteneurs répondent en général sous 1 jour
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`Peut-être pris @rajnish-verma-22172 l’a pris il y a 12 jours. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
microsoft/TypeScript#64742 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindingsPeut-être pris @dmety l’a pris il y a 25 jours. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
microsoft/TypeScript#64661 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de microsoft/TypeScript
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
limitlessprojects/Go-Hybrid#3342 ·
Les mainteneurs répondent en général sous 1 jour
-
status/ready type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
buildpacks/pack#2733 ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
kind/bug needs-priority needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
konveyor/tackle2-hub#1166 · 1 commentaire ·
Les mainteneurs répondent en général sous 4 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
router-for-me/CLIProxyAPI#7209 ·
Les mainteneurs répondent en général sous 1 jour