-
-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More type-safe theme, themes and resolvedTheme? #149
Comments
Yeah, any theme can be used (https://github.com/pacocoursey/next-themes#more-than-light-and-dark-mode) so your patch would be a little too limiting. But I'm sure there's a solution with generics here, will leave this issue open to improve it |
Oh, that's true, I should have watched more carefully the docs 😅... But I'm glad you found a way to take this option into account too, ty! |
I've opened a PR with what I've understood from your comment, maybe we can iterate from there when you have time to review it :) |
Are there any updates for this? |
no solution ? |
Why not allow to extend the declaration types, similar to next-auth So it would look something like this in the declare module "next-theme" {
export type Themes = "dark" | "light" | "acme-theme"
} Otherwise yes, the simple solution is to have generics, but that means you need to pass it each time when using the hook, whereas with the types declaration it will be global, so better DX. |
Here is an example how I resolved it for our project where I know we only have a dark or light theme: declare module "next-themes" {
import { UseThemeProps } from "next-themes/dist/types.ts";
export { ThemeProvider } from "next-themes/dist";
type AugmentedUseThemeProps = UseThemeProps & {
themes: ("dark" | "light" | "system")[];
resolvedTheme?: "dark" | "light";
theme?: "dark" | "light" | "system";
systemTheme?: "dark" | "light";
};
export const useTheme: () => AugmentedUseThemeProps;
} |
I'm getting a |
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
[email protected]
for the project I'm working on.Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
As you can see I've added a more robust typing for themes, theme and resolvedTheme, I wonder if this is something that could be updated at package level instead of just patching it for my needs. Is there any other value for those properties and that's the reason because it's a string?
In case this could be added to the library, a better way (or at least I think so) would be using a type like:
And using it for the properties on the interface.
Thank you!
The text was updated successfully, but these errors were encountered: