microsoft / microsoft/TypeScript
Type variables in type abstractions are not properly concretized
@weswigham ya está trabajando en esto.
Desde el 24/1/2025.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
🔎 Search Terms
type variables unknown
🕗 Version & Regression Information
- This changed between versions 4.9.5 and 5.0.4.
⏯ Playground Link
💻 Code
const f = <X,>(g: <A,>(b: X) => X, s: X) => g(s);
const ret = f(<B,>(x: B) => 1, "str");
// ^? const ret: unknown
🙁 Actual behavior
No type error is reported and ret is inferred as unknown type.
🙂 Expected behavior
I think a type error is reported because the call to f attempts to concretize the type variable X not only as a number but also as a string. In fact, TypeScript 4.9.5 reported a type error.
Additional information about the issue
I am not sure that TypeScript 4.9.5 was perfect. The following code is inferred to be unknown, but I think string is correct. This behavior was back to TypeScript 3.5.1.
const f = <X,>(g: <A,>(b: X) => X, s: X) => g(s);
const ret = f(<B,>(x: B) => x, "str");
// ^? const ret: unknown
// actual: ret is inferred as unknown
// expected: ret is inferred as string
I also found a strange behavior that a type variable that should have been concretized was returned without being concretized. I thought this is related, but I could be wrong. Sorry if so.
const f = <X,>(g: <A,>(x: X) => X) => g<string>;
const h = f<number>(<B,>(x: number) => 1);
// ^? const h: (x: X) => X
h(1);
// actual: type error
// expected: no type error
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.
Evaluación
Este issue todavía no se ha evaluado.