@@ -7,12 +7,12 @@ import {DataError} from "node-json-db/dist/lib/Errors.js";
77import type { z } from "zod" ;
88import { app , dialog } from "zulip:remote" ;
99
10- import { configSchemata } from "./config-schemata.ts" ;
10+ import { type ConfigSchemata , configSchemata } from "./config-schemata.ts" ;
1111import * as EnterpriseUtil from "./enterprise-util.ts" ;
1212import Logger from "./logger-util.ts" ;
1313
1414export type Config = {
15- [ Key in keyof typeof configSchemata ] : z . output < ( typeof configSchemata ) [ Key ] > ;
15+ [ Key in keyof ConfigSchemata ] : z . output < ConfigSchemata [ Key ] > ;
1616} ;
1717
1818const logger = new Logger ( {
@@ -26,7 +26,7 @@ reloadDatabase();
2626export function getConfigItem < Key extends keyof Config > (
2727 key : Key ,
2828 defaultValue : Config [ Key ] ,
29- ) : z . output < ( typeof configSchemata ) [ Key ] > {
29+ ) : z . output < ConfigSchemata [ Key ] > {
3030 try {
3131 database . reload ( ) ;
3232 } catch ( error : unknown ) {
@@ -35,7 +35,13 @@ export function getConfigItem<Key extends keyof Config>(
3535 }
3636
3737 try {
38- return configSchemata [ key ] . parse ( database . getObject < unknown > ( `/${ key } ` ) ) ;
38+ const typedSchemata : {
39+ [ Key in keyof Config ] : z . ZodType <
40+ z . output < ConfigSchemata [ Key ] > ,
41+ z . input < ConfigSchemata [ Key ] >
42+ > ;
43+ } = configSchemata ; // https://github.com/colinhacks/zod/issues/5154
44+ return typedSchemata [ key ] . parse ( database . getObject < unknown > ( `/${ key } ` ) ) ;
3945 } catch ( error : unknown ) {
4046 if ( ! ( error instanceof DataError ) ) throw error ;
4147 setConfigItem ( key , defaultValue ) ;
0 commit comments