[7.1 Regression] Unexpected behaviour change from Stronger Distributive Type checks
Mantenedores costumam responder em até 1 dia
Avaliação
Esta issue ainda não foi avaliada.
Descrição
🔎 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.
- Linguagem predominante
- Go
- Estrelas
- 112k
- Forks
- 15.4k
- Merge médio
- 2d 21h
- PRs com merge (30d)
- 126
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de microsoft/TypeScript
-
Won't Fix
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
microsoft/TypeScript#65107 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file locationTalvez já em andamento @timurzvural assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
microsoft/TypeScript#65087 ·
Mantenedores costumam responder em até 1 dia
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'Talvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. AbertaBug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
microsoft/TypeScript#64758 ·
Mantenedores costumam responder em até 1 dia
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`Talvez já em andamento @rajnish-verma-22172 assumiu há 13 dias. AbertaBug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
microsoft/TypeScript#64742 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindingsTalvez já em andamento @dmety assumiu há 26 dias. AbertaBug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
microsoft/TypeScript#64661 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de microsoft/TypeScript
Issues semelhantes
-
agent-butler-finding chore
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 78/100
jordansmall/spindrift#6318 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Eyevinn/moqlivemock#166 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
JakeChampion/lang#14091 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
hyperledger/fabric-x-orderer#1409 ·
Mantenedores costumam responder em até 3 dias
-
get actions doesn't show the approval flag, and describe action shows it unformattedTalvez já em andamento @kenokech assumiu hoje. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia