I have a list of jsons that I need to pull from a variety of sources. Some of those sources are dynamically generated from other jsons, and I'd like to have an object that describes that conversion, to be able to make the function that combines all the json sources more generic. That is to say, if I have
type Info = { a: string};
type Mation = { b: string};
type Data = { c: string};
type Jsons = {
"data.json": Data,
"mation.json": Mation,
"info.json": Info
}
const manifest = {
"data.json" : [{
sources: ["info.json", "mation.json"],
converter: infoToData
}]
}
function infoToData(info : Info, mation : Mation) : Data {
return {c: `${info.a},${mation.b}`;
}
How do I type manifest so that I get an error when the keys in sources and the parameters of converter don't line up?
I thought
type ManifestEntry<
Key extends keyof Jsons,
SourceKeys extends (keyof Jsons)[] = (keyof Jsons)[],
> = {
sources: SourceKeys;
converter: (
...sources: Partial[]
) => Partial;
};
const manifest: Partial<{
[Key in keyof JsonRecord]: ManifestEntry[];
}>
but it doesn't seem to actually fulfill the requirement