diff --git a/config/config.ts b/config/config.ts index 2c5e020..cd4ef3e 100644 --- a/config/config.ts +++ b/config/config.ts @@ -7,9 +7,10 @@ export class Config extends IBuilder { return new Config({}); } static withValue(key: K, value: Value) { - return new Config({ - [key]: value.build(), - } as { [key in K]: B }); + return Config.empty().withValue(key, value); + } + static addValue(key: K, value: Value) { + return Config.empty().withValue(key, value); } static of }, C extends ValueSpec>(spec: B) { diff --git a/config/list.ts b/config/list.ts index f2ffaad..1ed3a4b 100644 --- a/config/list.ts +++ b/config/list.ts @@ -1,4 +1,4 @@ -import { IBuilder } from "./builder.ts"; +import { BuilderExtract, IBuilder } from "./builder.ts"; import { Config } from "./config.ts"; import { Default, NullableDefault, NumberSpec, StringSpec } from "./value.ts"; import { Description } from "./value.ts"; @@ -50,19 +50,18 @@ export class List extends IBuilder { } static objectV< A extends Description & - NullableDefault[]> & { + Default[]> & { range: string; spec: { - spec: Config; + spec: Config; "display-as": null | string; "unique-by": null | UniqueBy; }; - }, - B extends ConfigSpec + } >(a: A) { const { spec: previousSpec, ...rest } = a; const { spec: previousSpecSpec, ...restSpec } = previousSpec; - const specSpec = previousSpecSpec.build(); + const specSpec = previousSpecSpec.build() as BuilderExtract; const spec = { ...restSpec, spec: specSpec, @@ -75,7 +74,7 @@ export class List extends IBuilder { type: "list" as const, subtype: "object" as const, ...value, - } as ValueSpecListOf<"object">); + }); } static union< A extends Description & @@ -90,17 +89,16 @@ export class List extends IBuilder { [key: string]: string; }; }; - variants: Variants; + variants: Variants<{ [key: string]: ConfigSpec }>; "display-as": null | string; "unique-by": UniqueBy; default: string; }; - }, - B extends { [key: string]: ConfigSpec } + } >(a: A) { const { spec: previousSpec, ...rest } = a; const { variants: previousVariants, ...restSpec } = previousSpec; - const variants = previousVariants.build(); + const variants = previousVariants.build() as BuilderExtract; const spec = { ...restSpec, variants, diff --git a/config/value.ts b/config/value.ts index c87d190..61dd24e 100644 --- a/config/value.ts +++ b/config/value.ts @@ -1,4 +1,4 @@ -import { IBuilder } from "./builder.ts"; +import { BuilderExtract, IBuilder } from "./builder.ts"; import { Config } from "./config.ts"; import { List } from "./list.ts"; import { Pointer } from "./pointer.ts"; @@ -9,6 +9,7 @@ import { ValueSpec, ValueSpecList, ValueSpecNumber, + ValueSpecObject, ValueSpecString, } from "../types/config-types.ts"; @@ -80,18 +81,20 @@ export class Value extends IBuilder { ...a, }); } - static objectV< - A extends Description & - NullableDefault<{ [k: string]: unknown }> & { - "display-as": null | string; - "unique-by": null | string; - spec: Config; - "value-names": Record; - }, - B extends ConfigSpec + static object< + A extends { + name: string; + description: string | null; + warning: string | null; + default: null | { [k: string]: unknown }; + "display-as": null | string; + "unique-by": null | string; + spec: Config; + "value-names": Record; + } >(a: A) { const { spec: previousSpec, ...rest } = a; - const spec = previousSpec.build(); + const spec = previousSpec.build() as BuilderExtract; return new Value({ type: "object" as const, ...rest, @@ -110,14 +113,13 @@ export class Value extends IBuilder { [key: string]: string; }; }; - variants: Variants; + variants: Variants<{ [key: string]: ConfigSpec }>; "display-as": string | null; "unique-by": UniqueBy; - }, - B extends { [key: string]: ConfigSpec } + } >(a: A) { const { variants: previousVariants, ...rest } = a; - const variants = previousVariants.build(); + const variants = previousVariants.build() as BuilderExtract; return new Value({ type: "union" as const, ...rest, @@ -128,7 +130,7 @@ export class Value extends IBuilder { static pointer(a: Pointer) { return new Value(a.build()); } - static list, B extends ValueSpecList>(a: A) { + static list>(a: A) { return new Value(a.build()); } } diff --git a/types/config-types.ts b/types/config-types.ts index 6eb6275..e7d2c8c 100644 --- a/types/config-types.ts +++ b/types/config-types.ts @@ -135,7 +135,7 @@ export interface ListValueSpecEnum { export interface ListValueSpecObject { spec: ConfigSpec; // this is a mapped type of the config object at this level, replacing the object's values with specs on those values "unique-by": UniqueBy; // indicates whether duplicates can be permitted in the list - "display-as"?: string; // this should be a handlebars template which can make use of the entire config which corresponds to 'spec' + "display-as"?: null | string; // this should be a handlebars template which can make use of the entire config which corresponds to 'spec' } export type UniqueBy = diff --git a/utils/propertiesMatcher.ts b/utils/propertiesMatcher.ts index 636ab6e..b0c4395 100644 --- a/utils/propertiesMatcher.ts +++ b/utils/propertiesMatcher.ts @@ -52,7 +52,7 @@ type GuardList = // prettier-ignore // deno-fmt-ignore type GuardPointer = - A extends {readonly type:TypePointer} ? {_UNKNOWN: "Pointer"} : + A extends {readonly type:TypePointer} ? (string | null) : unknown // prettier-ignore // deno-fmt-ignore