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

impr(typing): infer automatically the typing of the generators used inside of the compose #358

Merged
Merged
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
10 changes: 8 additions & 2 deletions packages/system/src/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Mixin,
StyleOptions,
CSSOption,
StyleGeneratorPropsConcat,
} from './types'

let themeGetterId = 0
Expand Down Expand Up @@ -224,9 +225,14 @@ const sortStyles = (
return styles
}

export const compose = <TProps = {}>(
export function compose<TProps = {}>(
...generators: StyleGenerator[]
): StyleGenerator<TProps> => {
): StyleGenerator<TProps>
export function compose<T extends StyleGenerator[]>(
...generators: T
): StyleGenerator<StyleGeneratorPropsConcat<T>>

export function compose(...generators: any[]): any {
let flatGenerators: StyleGenerator[] = []

generators.forEach((gen) => {
Expand Down
10 changes: 6 additions & 4 deletions packages/system/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ export type ThemeGetterType<T extends ThemeGetter> = T extends ThemeGetter<
? T
: never

export type StyleGeneratorProps<T extends object> = T extends StyleGenerator<
infer T
>
? T
export type StyleGeneratorProps<T> = T extends StyleGenerator<infer Props>
? Props
: never

export type StyleGeneratorPropsConcat<T> = T extends [infer Head, ...infer Tail]
? StyleGeneratorProps<Head> & StyleGeneratorPropsConcat<Tail>
: unknown