diff --git a/types/config.d.ts b/types/config.d.ts index ef2a8f4bc35b..9460884422e6 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -13,9 +13,53 @@ interface RecursiveKeyValuePair { } type ResolvableTo = T | ((utils: PluginUtils) => T) +type DotNotation = K extends string + ? T[K] extends Record + ? T[K] extends any[] + ? K | `${K}.${DotNotation>}` + : K | `${K}.${DotNotation}` + : K + : never +type Path = DotNotation | keyof T +type PathValue> = P extends `${infer K}.${infer Rest}` + ? K extends keyof T + ? Rest extends Path + ? PathValue + : never + : never + : P extends keyof T + ? T[P] + : never + +// Removes arbitrary values like: { [key: string]: any } +type WithoutStringKey = { [K in keyof T as string extends K ? never : K]: T[K] } + +type Unpack = T extends ResolvableTo + ? { [K in keyof R]: Unpack } + : T extends object + ? { [K in keyof T]: Unpack } + : T + +// This will remove all the callbacks and simplify it to the actual object +// it uses or the object it returns. It will also remove the `extend` +// section because at runtime that's gone anyway. +type UnpackedTheme = Omit>, 'extend'> + +// This will add additional information purely for code completion. E.g.: +type AugmentedTheme = Expand & { colors: DefaultColors }> + interface PluginUtils { colors: DefaultColors - theme(path: string, defaultValue: unknown): keyof ThemeConfig + + // Dynamic based on (default) theme config + theme

, TDefaultValue>( + path: P, + defaultValue?: TDefaultValue + ): PathValue + // Path is just a string, useful for third party plugins where we don't + // know the resulting type without generics. + theme(path: string, defaultValue?: TDefaultValue): TDefaultValue + breakpoints, O = I>(arg: I): O rgb(arg: string): (arg: Partial<{ opacityVariable: string; opacityValue: number }>) => string hsl(arg: string): (arg: Partial<{ opacityVariable: string; opacityValue: number }>) => string