diff --git a/.changeset/silver-toys-roll.md b/.changeset/silver-toys-roll.md new file mode 100644 index 0000000000..190623c482 --- /dev/null +++ b/.changeset/silver-toys-roll.md @@ -0,0 +1,6 @@ +--- +"@latticexyz/store": patch +"@latticexyz/world": patch +--- + +`defineStore` and `defineWorld` will now throw a type error if an unexpected config option is used. diff --git a/packages/store/ts/config/v2/store.test.ts b/packages/store/ts/config/v2/store.test.ts index 458f356d6a..0faf3c999e 100644 --- a/packages/store/ts/config/v2/store.test.ts +++ b/packages/store/ts/config/v2/store.test.ts @@ -516,4 +516,13 @@ describe("defineStore", () => { defineStore(config); }); + + it("should throw if config has unexpected key", () => { + attest(() => + defineStore({ + // @ts-expect-error Invalid config option + invalidOption: "nope", + }), + ).type.errors("`invalidOption` is not a valid Store config option."); + }); }); diff --git a/packages/store/ts/config/v2/store.ts b/packages/store/ts/config/v2/store.ts index 2305f2fba4..0922998f56 100644 --- a/packages/store/ts/config/v2/store.ts +++ b/packages/store/ts/config/v2/store.ts @@ -1,4 +1,4 @@ -import { flatMorph, narrow } from "@arktype/util"; +import { ErrorMessage, flatMorph, narrow } from "@arktype/util"; import { get, hasOwnKey, mergeIfUndefined } from "./generics"; import { UserTypes } from "./output"; import { CONFIG_DEFAULTS } from "./defaults"; @@ -23,7 +23,7 @@ export type validateStore = { ? narrow : key extends keyof StoreInput ? StoreInput[key] - : never; + : ErrorMessage<`\`${key & string}\` is not a valid Store config option.`>; }; export function validateStore(store: unknown): asserts store is StoreInput { diff --git a/packages/world/ts/config/v2/world.test.ts b/packages/world/ts/config/v2/world.test.ts index 94ab0f6842..245e9c9e26 100644 --- a/packages/world/ts/config/v2/world.test.ts +++ b/packages/world/ts/config/v2/world.test.ts @@ -752,4 +752,13 @@ describe("defineWorld", () => { defineWorld(config); }); + + it("should throw if config has unexpected key", () => { + attest(() => + defineWorld({ + // @ts-expect-error Invalid config option + invalidOption: "nope", + }), + ).type.errors("`invalidOption` is not a valid World config option."); + }); }); diff --git a/packages/world/ts/config/v2/world.ts b/packages/world/ts/config/v2/world.ts index 13898d5542..b26b358677 100644 --- a/packages/world/ts/config/v2/world.ts +++ b/packages/world/ts/config/v2/world.ts @@ -33,7 +33,7 @@ export type validateWorld = { ErrorMessage<`Namespaces config will be enabled soon.`> : key extends keyof WorldInput ? conform - : world[key]; + : ErrorMessage<`\`${key & string}\` is not a valid World config option.`>; }; export function validateWorld(world: unknown): asserts world is WorldInput {