Skip to content

Commit

Permalink
Reorder defineProperties function overload (#156)
Browse files Browse the repository at this point in the history
* Reorder defineProperties function overload

* changeset

* add snapshot version workflow

* Revert "add snapshot version workflow"

This reverts commit 0932a03.

* update lockfile

---------

Co-authored-by: Rogin Farrer <[email protected]>
  • Loading branch information
roginfarrer and Rogin Farrer authored Jan 4, 2024
1 parent 16b60b1 commit 98dc1ed
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-taxis-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rainbow-sprinkles': patch
---

Fixed complex type errors related to the permutations of configuration. See use #101 for example.
157 changes: 108 additions & 49 deletions packages/rainbow-sprinkles/src/defineProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,123 +78,182 @@ type ReturnShorthands<
};
};

type ShorthandOptions<
Properties extends object,
Shorthands extends { [shorthandName: string]: Array<keyof Properties> },
> = {
shorthands?: Shorthands;
};

export type OptionsConditionalDynamic<
DynamicProperties extends ConfigDynamicProperties,
Conditions extends ConfigConditions,
Shorthands extends { [k: string]: Array<keyof DynamicProperties> },
> = {
dynamicProperties: DynamicProperties;
conditions: Conditions;
defaultCondition: keyof Conditions;
shorthands?: Shorthands;
};
export type OptionsConditionalStatic<
StaticProperties extends ConfigStaticProperties,
Conditions extends ConfigConditions,
Shorthands extends { [k: string]: Array<keyof StaticProperties> },
> = {
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, StaticProperties>,
> = {
dynamicProperties: DynamicProperties;
staticProperties: StaticProperties;
conditions: Conditions;
defaultCondition: keyof Conditions;
shorthands?: Shorthands;
};
export type OptionsDynamic<
DynamicProperties extends ConfigDynamicProperties,
Shorthands extends { [k: string]: Array<keyof DynamicProperties> },
> = {
dynamicProperties: DynamicProperties;
shorthands?: Shorthands;
};
export type OptionsStatic<
StaticProperties extends ConfigStaticProperties,
Shorthands extends { [k: string]: Array<keyof StaticProperties> },
> = {
export type OptionsDynamic<DynamicProperties extends ConfigDynamicProperties> =
{
dynamicProperties: DynamicProperties;
};
export type OptionsStatic<StaticProperties extends ConfigStaticProperties> = {
staticProperties: StaticProperties;
shorthands?: Shorthands;
};
export type OptionsBoth<
DynamicProperties extends ConfigDynamicProperties,
StaticProperties extends ConfigStaticProperties,
Shorthands extends ConfigShorthands<DynamicProperties, StaticProperties>,
> = {
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<DynamicProperties>,
): ReturnDynamic<DynamicProperties>;
// Static Properties
export function defineProperties<
StaticProperties extends ConfigStaticProperties,
>(
options: CommonOptions & OptionsStatic<StaticProperties>,
): ReturnStatic<StaticProperties>;
// Dynamic Properties + Static Properties
export function defineProperties<
DynamicProperties extends ConfigDynamicProperties,
StaticProperties extends ConfigStaticProperties,
>(
options: CommonOptions & OptionsBoth<DynamicProperties, StaticProperties>,
): ReturnStatic<StaticProperties> & ReturnDynamic<DynamicProperties>;

/**
* SHORTHANDS + NO CONDITIONS
*/

// Dynamic Properties + Shorthands
export function defineProperties<
DynamicProperties extends ConfigDynamicProperties,
Conditions extends ConfigConditions,
Shorthands extends { [k: string]: Array<keyof DynamicProperties> },
>(
options: CommonOptions &
OptionsConditionalDynamic<DynamicProperties, Conditions, Shorthands>,
): ReturnConditionalDynamic<DynamicProperties, Conditions> &
ReturnShorthands<Shorthands>;
// Conditional Static Properties + Shorthands
OptionsDynamic<DynamicProperties> &
ShorthandOptions<DynamicProperties, Shorthands>,
): ReturnDynamic<DynamicProperties> & ReturnShorthands<Shorthands>;
// Static Properties + Shorthands
export function defineProperties<
StaticProperties extends ConfigStaticProperties,
Conditions extends ConfigConditions,
Shorthands extends { [k: string]: Array<keyof StaticProperties> },
>(
options: CommonOptions &
OptionsConditionalStatic<StaticProperties, Conditions, Shorthands>,
): ReturnConditionalStatic<StaticProperties, Conditions> &
OptionsStatic<StaticProperties> &
ShorthandOptions<StaticProperties, Shorthands>,
): ReturnStatic<StaticProperties> & ReturnShorthands<Shorthands>;
// Dynamic Properties + Static Properties + Shorthands
export function defineProperties<
DynamicProperties extends ConfigDynamicProperties,
StaticProperties extends ConfigStaticProperties,
Shorthands extends ConfigShorthands<DynamicProperties, StaticProperties>,
>(
options: CommonOptions &
OptionsBoth<DynamicProperties, StaticProperties> &
ShorthandOptions<DynamicProperties & StaticProperties, Shorthands>,
): ReturnStatic<StaticProperties> &
ReturnDynamic<DynamicProperties> &
ReturnShorthands<Shorthands>;
// 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<DynamicProperties, Conditions>,
): ReturnConditionalDynamic<DynamicProperties, Conditions>;
// Conditional Static Properties
export function defineProperties<
StaticProperties extends ConfigStaticProperties,
Conditions extends ConfigConditions,
>(
options: CommonOptions &
OptionsConditionalStatic<StaticProperties, Conditions>,
): ReturnConditionalStatic<StaticProperties, Conditions>;
// Conditional Dynamic Properties + Conditional Static Properties
export function defineProperties<
DynamicProperties extends ConfigDynamicProperties,
StaticProperties extends ConfigStaticProperties,
Conditions extends ConfigConditions,
Shorthands extends ConfigShorthands<DynamicProperties, StaticProperties>,
>(
options: CommonOptions &
OptionsConditionalBoth<
DynamicProperties,
StaticProperties,
Conditions,
Shorthands
>,
OptionsConditionalBoth<DynamicProperties, StaticProperties, Conditions>,
): ReturnConditionalStatic<StaticProperties, Conditions> &
ReturnConditionalDynamic<DynamicProperties, Conditions> &
ReturnShorthands<Shorthands>;
// Dynamic Properties + Shorthands
ReturnConditionalDynamic<DynamicProperties, Conditions>;

/**
* SHORTHANDS + CONDITIONS
*/

// Conditional Dynamic Properties + Shorthands
export function defineProperties<
DynamicProperties extends ConfigDynamicProperties,
Conditions extends ConfigConditions,
Shorthands extends { [k: string]: Array<keyof DynamicProperties> },
>(
options: CommonOptions & OptionsDynamic<DynamicProperties, Shorthands>,
): ReturnDynamic<DynamicProperties> & ReturnShorthands<Shorthands>;
// Static Properties + Shorthands
options: CommonOptions &
OptionsConditionalDynamic<DynamicProperties, Conditions> &
ShorthandOptions<DynamicProperties, Shorthands>,
): ReturnConditionalDynamic<DynamicProperties, Conditions> &
ReturnShorthands<Shorthands>;
// Conditional Static Properties + Shorthands
export function defineProperties<
StaticProperties extends ConfigStaticProperties,
Conditions extends ConfigConditions,
Shorthands extends { [k: string]: Array<keyof StaticProperties> },
>(
options: CommonOptions & OptionsStatic<StaticProperties, Shorthands>,
): ReturnStatic<StaticProperties> & ReturnShorthands<Shorthands>;
// Dynamic Properties + Static Properties + Shorthands
options: CommonOptions &
OptionsConditionalStatic<StaticProperties, Conditions> &
ShorthandOptions<StaticProperties, Shorthands>,
): ReturnConditionalStatic<StaticProperties, Conditions> &
ReturnShorthands<Shorthands>;
// Conditional Dynamic Properties + Conditional Static Properties + Shorthands
export function defineProperties<
DynamicProperties extends ConfigDynamicProperties,
StaticProperties extends ConfigStaticProperties,
Conditions extends ConfigConditions,
Shorthands extends ConfigShorthands<DynamicProperties, StaticProperties>,
>(
options: CommonOptions &
OptionsBoth<DynamicProperties, StaticProperties, Shorthands>,
): ReturnStatic<StaticProperties> &
ReturnDynamic<DynamicProperties> &
OptionsConditionalBoth<DynamicProperties, StaticProperties, Conditions> &
ShorthandOptions<DynamicProperties & StaticProperties, Shorthands>,
): ReturnConditionalStatic<StaticProperties, Conditions> &
ReturnConditionalDynamic<DynamicProperties, Conditions> &
ReturnShorthands<Shorthands>;
export function defineProperties(options: any): any {
const {
Expand Down

0 comments on commit 98dc1ed

Please sign in to comment.