TypeScript
Unanswered
Blue Picardy Spaniel posted this in #help-forum
Blue Picardy SpanielOP
import { z } from "zod";
const baseModule = z.object({
enabled: z.boolean()
});
// Modules
const globalBanModule = baseModule.extend({
autoSyncGlobalBans: z.string().optional(),
globalBanLogChannel: z.string().optional()
}).optional();
const webhookProtectionModule = baseModule.extend({
ignoredRoles: z.array(z.string()).optional(),
ignoreVerifiedBots: z.string().optional()
}).optional();
// Finalisation
export const settingsSchema = z.object({
globalBans: globalBanModule,
webhookProtection: webhookProtectionModule
});
export type Settings = z.infer<typeof settingsSchema>;
export type ModuleName = keyof Settings;
export type SettingKey<T extends ModuleName> = keyof Settings[T];
export type SettingValue<T extends ModuleName, K extends SettingKey<T>> = Settings[T][K];
Above is an extraction of my settings config.
I have a custom component which accepts a module name and a setting key:
export default function CustomChannelSelect({
settingKey,
defaultValue
}: {
moduleName: ModuleName;
settingKey: SettingKey<ModuleName>;
}) {
}
Passing a module name works fine, however the settingKey has an error:
Type 'string' is not assignable to type 'never'.
Any ideas? I'm really not the best with TypeScript :/
1 Reply
Blue Picardy SpanielOP
bump