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

Fix useTheme hook type #23

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/types/stitches.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
7 changes: 7 additions & 0 deletions src/types/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;