Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
fix(typing): reduce Token type complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
z0al committed Nov 29, 2020
1 parent b7a20d9 commit 84f9081
Show file tree
Hide file tree
Showing 2 changed files with 363 additions and 1,226 deletions.
13 changes: 2 additions & 11 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Packages
import { UnionToIntersection, ValueOf, LiteralUnion } from 'type-fest';
import { UnionToIntersection, ValueOf } from 'type-fest';

// Ours
import { Theme } from './theme';
import createStyles from './style';
import createProps from './style/props';
import { builtinVariants } from './variants';

export type TokenInfo = {
variant: string;
Expand All @@ -22,17 +21,9 @@ export type Configuration = {
type Styles = UnionToIntersection<ReturnType<typeof createStyles>>;
type Props = UnionToIntersection<ReturnType<typeof createProps>>;

type Variant = LiteralUnion<
keyof UnionToIntersection<typeof builtinVariants>,
string
>;

type Token = keyof UnionToIntersection<Styles | Props>;

type TokenWithVariant =
| Token
| `${Variant}:${Token}`
| `${Variant}:${Variant}:${Token}`;
type TokenWithVariant = Token | `${string}:${Token}`;

type ExtractToken<T extends string> = T extends `${string}:${infer V}`
? V extends Token
Expand Down
Loading

0 comments on commit 84f9081

Please sign in to comment.