microsoft / microsoft/TypeScript
Simple Comparison of Generics not allowed?
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el enlace al TypeScript 3.8 Playground y la reproducción genérica test<A, B> del issue. Investiga el diagnóstico del comprobador de tipos al comparar one === two cuando A y B son parámetros de tipo independientes. Se considera completado cuando el comportamiento de la comparación o su diagnóstico coincide con la expectativa indicada, con cobertura para el ejemplo mostrado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100