diff --git a/packages/store/ts/config/v2/generics.ts b/packages/store/ts/config/v2/generics.ts index cd0d0edce0..201f356669 100644 --- a/packages/store/ts/config/v2/generics.ts +++ b/packages/store/ts/config/v2/generics.ts @@ -1,14 +1,9 @@ -export type get<input, key, defaultValue = undefined> = key extends keyof input ? input[key] : defaultValue; +export type get<input, key> = key extends keyof input ? input[key] : undefined; -export function get<input, key extends PropertyKey, defaultValue = undefined>( - input: input, - key: key, - defaultValue: defaultValue = undefined as defaultValue, -): get<input, key, defaultValue> { - return (typeof input === "object" && input != null && hasOwnKey(input, key) ? input[key] : defaultValue) as get< +export function get<input, key extends PropertyKey>(input: input, key: key): get<input, key> { + return (typeof input === "object" && input != null && hasOwnKey(input, key) ? input[key] : undefined) as get< input, - key, - defaultValue + key >; } diff --git a/packages/store/ts/config/v2/store.ts b/packages/store/ts/config/v2/store.ts index 952c2c9262..f117938d5b 100644 --- a/packages/store/ts/config/v2/store.ts +++ b/packages/store/ts/config/v2/store.ts @@ -89,7 +89,7 @@ export function scopeWithEnums<enums, scope extends AbiTypeScope = AbiTypeScope> export type extendedScope<input> = scopeWithEnums<get<input, "enums">, scopeWithUserTypes<get<input, "userTypes">>>; export function extendedScope<input>(input: input): extendedScope<input> { - return scopeWithEnums(get(input, "enums"), scopeWithUserTypes(get(input, "userTypes", undefined))); + return scopeWithEnums(get(input, "enums"), scopeWithUserTypes(get(input, "userTypes"))); } export type validateStoreConfig<input> = { diff --git a/packages/world/ts/config/v2/world.test.ts b/packages/world/ts/config/v2/world.test.ts index 2d55a003f8..4392952ce8 100644 --- a/packages/world/ts/config/v2/world.test.ts +++ b/packages/world/ts/config/v2/world.test.ts @@ -101,7 +101,7 @@ describe("resolveWorldConfig", () => { namespace: "", } as const; - attest<typeof expected>(config).snap(expected); + attest<typeof expected>(config).equals(expected); }); it("should resolve namespaced table config with user types and enums", () => { diff --git a/packages/world/ts/config/v2/world.ts b/packages/world/ts/config/v2/world.ts index ee3682a71f..d4780ca597 100644 --- a/packages/world/ts/config/v2/world.ts +++ b/packages/world/ts/config/v2/world.ts @@ -73,13 +73,13 @@ export type resolveWorldConfig<input> = evaluate< >; export function resolveWorldConfig<const input>(input: validateWorldConfig<input>): resolveWorldConfig<input> { - const namespaces = get(input, "namespaces", {}); + const namespaces = get(input, "namespaces") ?? {}; const scope = extendedScope(input); const namespacedTables = Object.fromEntries( Object.entries(namespaces) .map(([namespaceKey, namespace]) => { - const tables = get(namespace, "tables", {}); + const tables = get(namespace, "tables") ?? {}; return Object.entries(tables).map(([tableKey, table]) => [`${namespaceKey}__${tableKey}`, table]); }) .flat(), @@ -88,15 +88,15 @@ export function resolveWorldConfig<const input>(input: validateWorldConfig<input const resolvedNamespaces = Object.fromEntries( Object.entries(namespaces).map(([namespaceKey, namespace]) => [ namespaceKey, - { tables: resolveStoreTablesConfig(get(namespace, "tables", {}), scope) }, + { tables: resolveStoreTablesConfig(get(namespace, "tables") ?? {}, scope) }, ]), ); return { - tables: resolveStoreTablesConfig({ ...get(input, "tables", {}), ...namespacedTables }, scope), + tables: resolveStoreTablesConfig({ ...(get(input, "tables") ?? {}), ...namespacedTables }, scope), namespaces: resolvedNamespaces, - userTypes: get(input, "userTypes", {}), - enums: get(input, "enums", {}), - namespace: get(input, "namespace", ""), - } as unknown as resolveWorldConfig<input>; + userTypes: get(input, "userTypes") ?? {}, + enums: get(input, "enums") ?? {}, + namespace: get(input, "namespace") ?? "", + } as resolveWorldConfig<input>; }