From 226ed2e73312d54443b727eda600e229144e9f7b Mon Sep 17 00:00:00 2001 From: Kamal Bennani Date: Wed, 16 Mar 2022 00:48:21 +0100 Subject: [PATCH] impr(typing): infer automatically the typing of the generators used inside of the compose --- packages/system/src/style.ts | 10 ++++++++-- packages/system/src/types.ts | 10 ++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/system/src/style.ts b/packages/system/src/style.ts index e840ee58..082e4937 100644 --- a/packages/system/src/style.ts +++ b/packages/system/src/style.ts @@ -27,6 +27,7 @@ import { Mixin, StyleOptions, CSSOption, + StyleGeneratorPropsConcat, } from './types' let themeGetterId = 0 @@ -224,9 +225,14 @@ const sortStyles = ( return styles } -export const compose = ( +export function compose( ...generators: StyleGenerator[] -): StyleGenerator => { +): StyleGenerator +export function compose( + ...generators: T +): StyleGenerator> + +export function compose(...generators: any[]): any { let flatGenerators: StyleGenerator[] = [] generators.forEach((gen) => { diff --git a/packages/system/src/types.ts b/packages/system/src/types.ts index 4a6eba54..788ae267 100644 --- a/packages/system/src/types.ts +++ b/packages/system/src/types.ts @@ -142,8 +142,10 @@ export type ThemeGetterType = T extends ThemeGetter< ? T : never -export type StyleGeneratorProps = T extends StyleGenerator< - infer T -> - ? T +export type StyleGeneratorProps = T extends StyleGenerator + ? Props : never + +export type StyleGeneratorPropsConcat = T extends [infer Head, ...infer Tail] + ? StyleGeneratorProps & StyleGeneratorPropsConcat + : unknown