Skip to content

Commit acb49e4

Browse files
committed
undo all theme types, and type it as theme(path: string): any
Since currently we don't want to investigate time to make the code completion *perfect* (because it might be even impossible to do it properly due to resolving of overrides, extend and deeply nested presets) For now we will provide a way simpler type, which is better than incorrect types. So far we only had types for the default config theme *only*.
1 parent e918485 commit acb49e4

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

types/config.d.ts

+1-46
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,9 @@ interface RecursiveKeyValuePair<K extends keyof any = string, V = string> {
1313
}
1414
type ResolvableTo<T> = T | ((utils: PluginUtils) => T)
1515

16-
type DotNotation<T, K extends keyof T = keyof T> = K extends string
17-
? T[K] extends Record<string, any>
18-
? T[K] extends any[]
19-
? K | `${K}.${DotNotation<T[K], Exclude<keyof T[K], keyof any[]>>}`
20-
: K | `${K}.${DotNotation<T[K], keyof T[K]>}`
21-
: K
22-
: never
23-
type Path<T> = DotNotation<T> | keyof T
24-
type PathValue<T, P extends Path<T>> = P extends `${infer K}.${infer Rest}`
25-
? K extends keyof T
26-
? Rest extends Path<T[K]>
27-
? PathValue<T[K], Rest>
28-
: never
29-
: never
30-
: P extends keyof T
31-
? T[P]
32-
: never
33-
34-
// Removes arbitrary values like: { [key: string]: any }
35-
type WithoutStringKey<T> = { [K in keyof T as string extends K ? never : K]: T[K] }
36-
37-
type Unpack<T> = T extends ResolvableTo<infer R>
38-
? { [K in keyof R]: Unpack<R[K]> }
39-
: T extends object
40-
? { [K in keyof T]: Unpack<T[K]> }
41-
: T
42-
43-
// This will remove all the callbacks and simplify it to the actual object
44-
// it uses or the object it returns. It will also remove the `extend`
45-
// section because at runtime that's gone anyway.
46-
type UnpackedTheme = Omit<WithoutStringKey<Unpack<Config['theme']>>, 'extend'>
47-
48-
// This will add additional information purely for code completion. E.g.:
49-
type AugmentedTheme = Expand<Omit<UnpackedTheme, 'colors'> & { colors: DefaultColors }>
50-
5116
interface PluginUtils {
5217
colors: DefaultColors
53-
54-
// Dynamic based on (default) theme config
55-
theme<P extends Path<AugmentedTheme>, TDefaultValue>(
56-
path: P,
57-
defaultValue?: TDefaultValue
58-
): PathValue<AugmentedTheme, P>
59-
// Path is just a string, useful for third party plugins where we don't
60-
// know the resulting type without generics.
61-
theme<TDefaultValue = any>(path: string, defaultValue?: TDefaultValue): TDefaultValue
62-
18+
theme(path: string, defaultValue?: unknown): any
6319
breakpoints<I = Record<string, unknown>, O = I>(arg: I): O
6420
rgb(arg: string): (arg: Partial<{ opacityVariable: string; opacityValue: number }>) => string
6521
hsl(arg: string): (arg: Partial<{ opacityVariable: string; opacityValue: number }>) => string
@@ -367,4 +323,3 @@ interface OptionalConfig {
367323
}
368324

369325
export type Config = RequiredConfig & Partial<OptionalConfig>
370-

0 commit comments

Comments
 (0)