chore: Make the expanded types extended, so that way we know we are outputing the correct type.

This commit is contained in:
BluJ
2023-02-13 10:36:11 -07:00
parent 894084db5b
commit c685e9e169
5 changed files with 68 additions and 53 deletions

View File

@@ -1,17 +1,18 @@
import { ConfigSpec, ValueSpecAny } from "../types.ts";
import { BuilderExtract, IBuilder } from "./builder.ts";
import { Value } from "./value.ts";
export class Config<A> extends IBuilder<A> {
export class Config<A extends ConfigSpec> extends IBuilder<A> {
static empty() {
return new Config({});
}
static withValue<K extends string, B>(key: K, value: Value<B>) {
static withValue<K extends string, B extends ValueSpecAny>(key: K, value: Value<B>) {
return new Config({
[key]: value.build(),
} as { [key in K]: B });
}
static of<B extends { [key: string]: Value<unknown> }>(spec: B) {
static of<B extends { [key: string]: Value<C> }, C extends ValueSpecAny>(spec: B) {
// deno-lint-ignore no-explicit-any
const answer: { [K in keyof B]: BuilderExtract<B[K]> } = {} as any;
for (const key in spec) {
@@ -20,7 +21,7 @@ export class Config<A> extends IBuilder<A> {
}
return new Config(answer);
}
addValue<K extends string, B>(key: K, value: Value<B>) {
addValue<K extends string, B extends ValueSpecAny>(key: K, value: Value<B>) {
return new Config({
...this.a,
[key]: value.build(),