This commit is contained in:
Matt Hill
2023-03-27 15:35:20 -06:00
parent 5e2d87c11b
commit 42951b4fa2
7 changed files with 101 additions and 88 deletions

View File

@@ -41,22 +41,25 @@ import { Config } from ".";
export class Variants<
A extends {
[key: string]: {
name: string,
spec: InputSpec
}
name: string;
spec: InputSpec;
};
}
> extends IBuilder<A> {
static of<
A extends {
[key: string]: { name: string, spec: Config<InputSpec> };
[key: string]: { name: string; spec: Config<InputSpec> };
}
>(a: A) {
const variants: { [K in keyof A]: { name: string, spec: BuilderExtract<A[K]['spec']> } } = {} as any;
const variants: {
[K in keyof A]: { name: string; spec: BuilderExtract<A[K]["spec"]> };
} = {} as any;
for (const key in a) {
const value = a[key]
const value = a[key];
variants[key] = {
name: value.name, spec: value.spec.build() as any
}
name: value.name,
spec: value.spec.build() as any,
};
}
return new Variants(variants);
}