resolveConfig.d.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import { Config, ResolvableTo, ThemeConfig } from './types/config'
  2. import { DefaultTheme } from './types/generated/default-theme'
  3. import { DefaultColors } from './types/generated/colors'
  4. type ResolvedConfig<T extends Config> = Omit<T, 'theme'> & {
  5. theme: MergeThemes<
  6. UnwrapResolvables<Omit<T['theme'], 'extend'>>,
  7. T['theme'] extends { extend: infer TExtend } ? UnwrapResolvables<TExtend> : {}
  8. >
  9. }
  10. type UnwrapResolvables<T> = {
  11. [K in keyof T]: T[K] extends ResolvableTo<infer R> ? R : T[K]
  12. }
  13. type ThemeConfigResolved = UnwrapResolvables<ThemeConfig>
  14. type DefaultThemeFull = DefaultTheme & { colors: DefaultColors }
  15. type MergeThemes<Overrides extends object, Extensions extends object> = {
  16. [K in keyof ThemeConfigResolved | keyof Overrides]: (K extends keyof Overrides
  17. ? Overrides[K]
  18. : K extends keyof DefaultThemeFull
  19. ? DefaultThemeFull[K]
  20. : K extends keyof ThemeConfigResolved
  21. ? ThemeConfigResolved[K]
  22. : never) &
  23. (K extends keyof Extensions ? Extensions[K] : {})
  24. }
  25. declare function resolveConfig<T extends Config>(config: T): ResolvedConfig<T>
  26. export = resolveConfig