Skip to content

Commit

Permalink
feat(css): improve autocomplete resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Sep 8, 2022
1 parent 35e5b89 commit 1861864
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/types/theme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NestedKeyOf, WrapUnion } from '.'
import type { FilterStartingWith, WrapUnion } from '.'
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
// @ts-ignore - Can be not found
import type { GeneratedPinceauTheme, GeneratedTokensPaths } from '#pinceau/types'
Expand Down Expand Up @@ -237,9 +237,13 @@ export interface DefaultThemeMap {

export interface PinceauTheme extends GeneratedPinceauTheme, Omit<GlobalTokens, keyof GeneratedPinceauTheme>, PinceauTokens {}

export type PinceauThemePaths = {} & GeneratedTokensPaths
export type PinceauThemePaths = GeneratedTokensPaths

export type ThemeKey<K extends keyof DefaultThemeMap> = WrapUnion<NestedKeyOf<PinceauTheme[DefaultThemeMap[K]]>, `{${DefaultThemeMap[K]}.`, '}'>
// Old version; slower and relying on recursively walking through typing object
// export type ThemeKey<K extends keyof DefaultThemeMap> = WrapUnion<NestedKeyOf<PinceauTheme[DefaultThemeMap[K]]>, `{${DefaultThemeMap[K]}.`, '}'>

// Resolve available theme tokens for a key from theme map and generated theme paths
export type ThemeKey<K extends keyof DefaultThemeMap> = WrapUnion<FilterStartingWith<PinceauThemePaths, DefaultThemeMap[K]>, '{', '}'>

export interface TokensFunctionOptions {
/**
Expand Down
3 changes: 3 additions & 0 deletions src/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export type NestedKeyOf<TObject> =
: `${Key}`
}[keyof TObject & (string | number)]

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type FilterStartingWith<Set, Needle extends string> = Set extends `${Needle}${infer _X}` ? Set : never

export type WrapUnion<
TObject extends string,
TPrefix extends string,
Expand Down

0 comments on commit 1861864

Please sign in to comment.