The satisfies Operator for Config Objects
Use satisfies to check a config literal against a broad type while preserving its literal inference, catching typos without widening values.
Code
type Theme = "light" | "dark" | "system";
interface AppConfig {
theme: Theme;
locale: string;
features: Record<string, boolean>;
}
export const config = {
theme: "dark",
locale: "en-US",
features: { search: true, beta: false },
} satisfies AppConfig;
// config.theme is inferred as "dark", not widened to Theme:
export type ThemeValue = typeof config.theme;
export function resolveTheme(value: ThemeValue, prefersDark: boolean): "light" | "dark" {
if (value === "system") return prefersDark ? "dark" : "light";
return value;
}Report a problem with this exampleOpens a pre-filled issue on GitHub.