diff --git a/src/types/stitches.d.ts b/src/types/stitches.d.ts index d7d18bb..87db72e 100644 --- a/src/types/stitches.d.ts +++ b/src/types/stitches.d.ts @@ -48,7 +48,11 @@ export default interface Stitches< useTheme: () => string & { [Scale in keyof Theme]: { - [Token in keyof Theme[Scale]]: number | string; + [Token in keyof Theme[Scale]]: Theme[Scale][Token] extends string + ? Util.AliasedToken<Theme[Scale][Token]> extends never + ? string + : Theme[Scale][Util.AliasedToken<Theme[Scale][Token]>] + : Theme[Scale][Token]; }; }; ThemeProvider: React.FunctionComponent<{ theme?: any }>; // TODO: fix `any` diff --git a/src/types/util.d.ts b/src/types/util.d.ts index 2ad0f88..c22e753 100644 --- a/src/types/util.d.ts +++ b/src/types/util.d.ts @@ -36,3 +36,10 @@ export type Function = (...args: any[]) => unknown; export type WideObject = { [name in number | string]: boolean | number | string | undefined | WideObject; }; + +/* Util for aliases tokens. Returns the aliased token if it's an alias, returns never if it's not. */ +export type AliasedToken<V extends string> = V extends `${infer Head}${infer Tail}` + ? Head extends "$" + ? Tail + : never + : never; \ No newline at end of file