diff --git a/.changeset/tasty-taxis-end.md b/.changeset/tasty-taxis-end.md new file mode 100644 index 00000000..ba1940a8 --- /dev/null +++ b/.changeset/tasty-taxis-end.md @@ -0,0 +1,5 @@ +--- +'rainbow-sprinkles': patch +--- + +Fixed complex type errors related to the permutations of configuration. See use #101 for example. diff --git a/packages/rainbow-sprinkles/src/defineProperties.ts b/packages/rainbow-sprinkles/src/defineProperties.ts index 69166171..ce58c343 100644 --- a/packages/rainbow-sprinkles/src/defineProperties.ts +++ b/packages/rainbow-sprinkles/src/defineProperties.ts @@ -78,123 +78,182 @@ type ReturnShorthands< }; }; +type ShorthandOptions< + Properties extends object, + Shorthands extends { [shorthandName: string]: Array }, +> = { + shorthands?: Shorthands; +}; + export type OptionsConditionalDynamic< DynamicProperties extends ConfigDynamicProperties, Conditions extends ConfigConditions, - Shorthands extends { [k: string]: Array }, > = { dynamicProperties: DynamicProperties; conditions: Conditions; defaultCondition: keyof Conditions; - shorthands?: Shorthands; }; export type OptionsConditionalStatic< StaticProperties extends ConfigStaticProperties, Conditions extends ConfigConditions, - Shorthands extends { [k: string]: Array }, > = { staticProperties: StaticProperties; conditions: Conditions; defaultCondition: keyof Conditions; - shorthands?: Shorthands; }; export type OptionsConditionalBoth< DynamicProperties extends ConfigDynamicProperties, StaticProperties extends ConfigStaticProperties, Conditions extends ConfigConditions, - Shorthands extends ConfigShorthands, > = { dynamicProperties: DynamicProperties; staticProperties: StaticProperties; conditions: Conditions; defaultCondition: keyof Conditions; - shorthands?: Shorthands; -}; -export type OptionsDynamic< - DynamicProperties extends ConfigDynamicProperties, - Shorthands extends { [k: string]: Array }, -> = { - dynamicProperties: DynamicProperties; - shorthands?: Shorthands; }; -export type OptionsStatic< - StaticProperties extends ConfigStaticProperties, - Shorthands extends { [k: string]: Array }, -> = { +export type OptionsDynamic = + { + dynamicProperties: DynamicProperties; + }; +export type OptionsStatic = { staticProperties: StaticProperties; - shorthands?: Shorthands; }; export type OptionsBoth< DynamicProperties extends ConfigDynamicProperties, StaticProperties extends ConfigStaticProperties, - Shorthands extends ConfigShorthands, > = { dynamicProperties: DynamicProperties; staticProperties: StaticProperties; - shorthands?: Shorthands; }; -// Conditional Dynamic Properties + Shorthands +/** + * NO SHORTHANDS + NO CONDITIONS + */ + +// Dynamic Properties +export function defineProperties< + DynamicProperties extends ConfigDynamicProperties, +>( + options: CommonOptions & OptionsDynamic, +): ReturnDynamic; +// Static Properties +export function defineProperties< + StaticProperties extends ConfigStaticProperties, +>( + options: CommonOptions & OptionsStatic, +): ReturnStatic; +// Dynamic Properties + Static Properties +export function defineProperties< + DynamicProperties extends ConfigDynamicProperties, + StaticProperties extends ConfigStaticProperties, +>( + options: CommonOptions & OptionsBoth, +): ReturnStatic & ReturnDynamic; + +/** + * SHORTHANDS + NO CONDITIONS + */ + +// Dynamic Properties + Shorthands export function defineProperties< DynamicProperties extends ConfigDynamicProperties, - Conditions extends ConfigConditions, Shorthands extends { [k: string]: Array }, >( options: CommonOptions & - OptionsConditionalDynamic, -): ReturnConditionalDynamic & - ReturnShorthands; -// Conditional Static Properties + Shorthands + OptionsDynamic & + ShorthandOptions, +): ReturnDynamic & ReturnShorthands; +// Static Properties + Shorthands export function defineProperties< StaticProperties extends ConfigStaticProperties, - Conditions extends ConfigConditions, Shorthands extends { [k: string]: Array }, >( options: CommonOptions & - OptionsConditionalStatic, -): ReturnConditionalStatic & + OptionsStatic & + ShorthandOptions, +): ReturnStatic & ReturnShorthands; +// Dynamic Properties + Static Properties + Shorthands +export function defineProperties< + DynamicProperties extends ConfigDynamicProperties, + StaticProperties extends ConfigStaticProperties, + Shorthands extends ConfigShorthands, +>( + options: CommonOptions & + OptionsBoth & + ShorthandOptions, +): ReturnStatic & + ReturnDynamic & ReturnShorthands; -// Conditional Dynamic Properties + Conditional Static Properties + Shorthands + +/** + * NO SHORTHANDS + CONDITIONS + */ + +// Conditional Dynamic Properties +export function defineProperties< + DynamicProperties extends ConfigDynamicProperties, + Conditions extends ConfigConditions, +>( + options: CommonOptions & + OptionsConditionalDynamic, +): ReturnConditionalDynamic; +// Conditional Static Properties +export function defineProperties< + StaticProperties extends ConfigStaticProperties, + Conditions extends ConfigConditions, +>( + options: CommonOptions & + OptionsConditionalStatic, +): ReturnConditionalStatic; +// Conditional Dynamic Properties + Conditional Static Properties export function defineProperties< DynamicProperties extends ConfigDynamicProperties, StaticProperties extends ConfigStaticProperties, Conditions extends ConfigConditions, - Shorthands extends ConfigShorthands, >( options: CommonOptions & - OptionsConditionalBoth< - DynamicProperties, - StaticProperties, - Conditions, - Shorthands - >, + OptionsConditionalBoth, ): ReturnConditionalStatic & - ReturnConditionalDynamic & - ReturnShorthands; -// Dynamic Properties + Shorthands + ReturnConditionalDynamic; + +/** + * SHORTHANDS + CONDITIONS + */ + +// Conditional Dynamic Properties + Shorthands export function defineProperties< DynamicProperties extends ConfigDynamicProperties, + Conditions extends ConfigConditions, Shorthands extends { [k: string]: Array }, >( - options: CommonOptions & OptionsDynamic, -): ReturnDynamic & ReturnShorthands; -// Static Properties + Shorthands + options: CommonOptions & + OptionsConditionalDynamic & + ShorthandOptions, +): ReturnConditionalDynamic & + ReturnShorthands; +// Conditional Static Properties + Shorthands export function defineProperties< StaticProperties extends ConfigStaticProperties, + Conditions extends ConfigConditions, Shorthands extends { [k: string]: Array }, >( - options: CommonOptions & OptionsStatic, -): ReturnStatic & ReturnShorthands; -// Dynamic Properties + Static Properties + Shorthands + options: CommonOptions & + OptionsConditionalStatic & + ShorthandOptions, +): ReturnConditionalStatic & + ReturnShorthands; +// Conditional Dynamic Properties + Conditional Static Properties + Shorthands export function defineProperties< DynamicProperties extends ConfigDynamicProperties, StaticProperties extends ConfigStaticProperties, + Conditions extends ConfigConditions, Shorthands extends ConfigShorthands, >( options: CommonOptions & - OptionsBoth, -): ReturnStatic & - ReturnDynamic & + OptionsConditionalBoth & + ShorthandOptions, +): ReturnConditionalStatic & + ReturnConditionalDynamic & ReturnShorthands; export function defineProperties(options: any): any { const {