Skip to content
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

Theme example #1

Open
orta opened this issue Feb 23, 2022 · 0 comments
Open

Theme example #1

orta opened this issue Feb 23, 2022 · 0 comments

Comments

@orta
Copy link
Contributor

orta commented Feb 23, 2022

I wondered if the multi-theme example got made TODO because of the issue with as const and having a literal type object. There's many possible answers to ensure your types match, but here's the one I use (because I keep Widen around for other uses). The docs for it are here

export const mainTheme = {
  primary: "blue",
  background: "white",
} as const

export const darkTheme: GeneralTheme = {
  primary: "white",
  backgrund: "black",
}

export type AppTheme = typeof mainTheme
export type GeneralTheme = Widen<typeof mainTheme>


type Widen<T> = { [key in keyof T]: ToPrimitive<T[key]> }

type ToPrimitive<T> = T extends string
  ? string
  : T extends number
  ? number
  : T extends boolean
  ? boolean
  : T extends (..._args: any[]) => any
  ? (..._args: Parameters<T>) => ReturnType<T>
  : T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant