Closed benkeen closed 1 year ago
From Stack Overflow:
enum Plugins {
A = "A",
B = "B",
//
};
interface OptionsMap {
[Plugins.A]: { x: string, y: number };
[Plugins.B]: { s: boolean, t: Date };
}
type Options = { [K in Plugins]: { plugin: K, options: OptionsMap[K] } }[Plugins]
const allOptions: Options[] = [
{
plugin: Plugins.A,
options: {
x: "",
y: 1
}
},
{
plugin: Plugins.B,
options: {
s: true,
t: new Date()
}
},
{
plugin: Plugins.A,
options: {
s: false, // error!
t: new Date()
}
}
]
Bit fussy & requires user to use enums instead of strings. Also it requires user to provide options: null
for certain DTs. Will deal with that later.
This is an early step in offering an npm package version of generate data.
See notes: https://github.com/benkeen/generatedata/blob/master/scripts/NPM-PACKAGE.md#schema-definition