diff --git a/packages/store/ts/config/v2/store.ts b/packages/store/ts/config/v2/store.ts index 029c527320..c0abc7a71b 100644 --- a/packages/store/ts/config/v2/store.ts +++ b/packages/store/ts/config/v2/store.ts @@ -2,7 +2,8 @@ import { ErrorMessage, evaluate, narrow } from "@arktype/util"; import { get, hasOwnKey, mergeIfUndefined } from "./generics"; import { UserTypes } from "./output"; import { CONFIG_DEFAULTS } from "./defaults"; -import { NamespaceInput, StoreInput } from "./input"; +import { StoreInput } from "./input"; +import { validateTables } from "./tables"; import { scopeWithUserTypes, validateUserTypes } from "./userTypes"; import { mapEnums, resolveEnums, scopeWithEnums } from "./enums"; import { resolveCodegen } from "./codegen"; @@ -14,16 +15,19 @@ export function extendedScope(input: input): extendedScope { return scopeWithEnums(get(input, "enums"), scopeWithUserTypes(get(input, "userTypes"))); } -export type validateStore = (input extends NamespaceInput - ? validateNamespace, extendedScope> - : {}) & { - [key in keyof input]: key extends "userTypes" - ? UserTypes - : key extends "enums" - ? narrow - : key extends keyof StoreInput - ? StoreInput[key] - : ErrorMessage<`\`${key & string}\` is not a valid Store config option.`>; +// Ideally we'd be able to use an intersection of `validateNamespace<...> & { ... }` to avoid +// duplicating logic, but TS doesn't work well when mapping over types like that. +// TODO: fill in more reasons why +export type validateStore = { + [key in keyof input]: key extends "tables" + ? validateTables> + : key extends "userTypes" + ? UserTypes + : key extends "enums" + ? narrow + : key extends keyof StoreInput + ? StoreInput[key] + : ErrorMessage<`\`${key & string}\` is not a valid Store config option.`>; }; export function validateStore(input: unknown): asserts input is StoreInput {