Skip to content

Type theme object using theme contract? #1328

Answered by rothsandro
MaximKondratev asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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 lightTheme.color.brand somewhere you will not just…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MaximKondratev
Comment options

Answer selected by MaximKondratev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants