Closed
Description
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms: mapped types generics bug
Code
I can confirm that this does not work:
const genericFunc = async <Schema extends { _id: string }>() => {
type a = { [K in keyof Schema]: Schema[K] };
const b: a = { _id: 'sd' };
}
And this does work:
type Schema2 = { _id: string };
type a2 = { [K in keyof Schema2]: Schema2[K] };
const b2: a2 = { _id: 'sd' };
Expected behavior:
IMO TypeScript should assume generic parameter above is something like this:
interface Schema {
_id: string;
[K: string]: any;
}
and does not throw errors.
Playground Link: example link
Related Issues: I'm one of the maintainers of the @types/mongodb
in definitely typed. This is the original issue DefinitelyTyped/DefinitelyTyped#39358