How can I iterate over exported types in a barrel?
Here I’d like Key
to be any of the exported type names in seeds
.
And I would like to be able to access types by name from a barrel import.
If I use keyof typeof seeds
, it’s stripping out all the types in seeds
Is it even possible?
For instance, with these files:
types.ts
export type TypeA = {
a: number;
b: string;
}
export type TypeB = {
c: number;
d: string;
}
index.ts
import * as types from './types';
type MyType = Partial<{
[Key in keyof types]: types[Key][];
}>;
I’d like MyType
to be
type MyType = Partial<{
"TypeA": TypeA[];
"TypeB": TypeB[]
}>;