microsoft / microsoft/TypeScript
Simple Comparison of Generics not allowed?
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
TypeScript Version: 3.8
Search Terms:
generic comparison
compare generic strings
Code
function test<A, B>(one: A, two: B): A {
if (one === two) {
throw new Error('no');
}
return one;
}
const obj = {};
test(obj, obj);
Expected behavior:
While the generics are generally indicating that one and two are independent values, they can still potentially be the same underlying value so they should be able to at least be checked for equality without casting them first, especially since there is no error produced when calling the function with identical values in the first place.
At the very least the error message should be more specific since the assumption it is providing is not correct in since the condition returns true :-P
( This is clearly a simplified version of where I ran into this since there'd be no reason to use generics in this specific case :-) )
Actual behavior:
Shown in example
Playground Link: Playground
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.
Direzione di ricerca
Inizia con il link a TypeScript 3.8 Playground e la riproduzione generica test<A, B> nell’issue. Analizza la diagnosi del type-checker durante il confronto di one === two quando A e B sono parametri di tipo indipendenti. Il lavoro è considerato completato quando il comportamento del confronto o la relativa diagnosi corrisponde all’aspettativa indicata, con una copertura per l’esempio mostrato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100