Type theme object using theme contract? #1328
-
I have 3 files:
export const contract = createGlobalThemeContract(
{
color: {
brand: null,
}
},
);
export const lightTheme = {
color: {
brand: 'red',
},
};
The question is how do I type type Contract = {
color: {
brand: string
}
}
export const lightTheme: Contract = { ... } but infering Contract type from contract itself. Right now we can not use something like |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Looks like the types needed for that are not exported by VE 😞 but as a workaround you can extract the types from the type Contract = ReturnType<typeof createGlobalThemeContract>;
type ContractOf<T extends Contract> = Parameters<typeof createGlobalTheme<T>>[2];
type ThemeContract = ContractOf<typeof contract>;
export const contract = createGlobalThemeContract({});
export const lightTheme: ThemeContract = { /* type-safe */ }; For the light theme you can also use the following syntax to keep the actual value: export const lightTheme = {
color: {
brand: "red"
}
} as const satisfies ThemeContract; If you use |
Beta Was this translation helpful? Give feedback.
Looks like the types needed for that are not exported by VE 😞 but as a workaround you can extract the types from the
createGlobalTheme
function:For the light theme you can also use the following syntax to keep the actual value:
If you use
lightTheme.color.brand
somewhere you will not just…