microsoft / microsoft/TypeScript
Incomplete infer for generic types
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
TypeScript Version: 4.0.5
Search Terms:
typescript, infer, incomplete, unknown, generic
Expected behavior:
The compiler should be able to extract information of the generic Item type from the function definition and infer string.
Actual behavior:
The compiler is able to infer the Names type as { id: string } but the Item type is unknown.
Related Issues:
Code
interface LoaderConfig<Key, Item> {
loadItems: (keys: readonly Key[]) => Promise<readonly Item[]>;
getKey: (item: Item) => Key;
makeCacheKey: (key: Key) => string;
}
type LoaderConfigByName<Names, Item> = {
[name in keyof Names]: LoaderConfig<Names[name], Item>;
};
function makeLoader<Names, Item>(
configs: LoaderConfigByName<Names, Item>
): void {
console.log(configs);
}
makeLoader({
id: {
loadItems: async (keys: readonly string[]): Promise<readonly string[]> => {
return await Promise.resolve(keys);
},
getKey: (item: string): string => item,
makeCacheKey: (key: string): string => {
return key;
}
}
});
Output
"use strict";
function makeLoader(configs) {
console.log(configs);
}
makeLoader({
id: {
loadItems: async (keys) => {
return await Promise.resolve(keys);
},
getKey: (item) => item,
makeCacheKey: (key) => {
return key;
}
}
});
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
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 proporcionado a Playground y el ejemplo genérico makeLoader usando TypeScript 4.0.5. Reproduce el resultado de la inferencia y sigue el tratamiento que hace el compilador del tipo genérico Item. Se considera completado cuando el ejemplo infiere Item como string y conserva el tipo Names inferido.
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
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 38/100