Skip to content

Commit

Permalink
[styles] Name anonymous function type (#19996)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 5, 2020
1 parent daa0eff commit 79d9099
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/material-ui-styles/src/withStyles/withStyles.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export {};

type JSSFontface = CSS.FontFace & { fallbacks?: CSS.FontFace[] };

type PropsFunc<Props extends object, T> = (props: Props) => T;

/**
* Allows the user to augment the properties available
*/
Expand All @@ -29,7 +31,7 @@ export interface CSSProperties extends BaseCSSProperties {
}

export type BaseCreateCSSProperties<Props extends object = {}> = {
[P in keyof BaseCSSProperties]: BaseCSSProperties[P] | ((props: Props) => BaseCSSProperties[P])
[P in keyof BaseCSSProperties]: BaseCSSProperties[P] | PropsFunc<Props, BaseCSSProperties[P]>
};

export interface CreateCSSProperties<Props extends object = {}>
Expand All @@ -55,7 +57,7 @@ export type StyleRules<Props extends object = {}, ClassKey extends string = stri
// JSS property bag where values are based on props
| CreateCSSProperties<Props>
// JSS property bag based on props
| ((props: Props) => CreateCSSProperties<Props>)
| PropsFunc<Props, CreateCSSProperties<Props>>
>;

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/material-ui-styles/test/styles.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,14 @@ function forwardRefTest() {
// If there are no props, use the definition that doesn't accept them
// https://github.com/mui-org/material-ui/issues/16198

// $ExpectType Record<"root", CSSProperties | CreateCSSProperties<{}> | ((props: {}) => CreateCSSProperties<{}>)>
// $ExpectType Record<"root", CSSProperties | CreateCSSProperties<{}> | PropsFunc<{}, CreateCSSProperties<{}>>>
const styles = createStyles({
root: {
width: 1,
},
});

// $ExpectType Record<"root", CSSProperties | CreateCSSProperties<{}> | ((props: {}) => CreateCSSProperties<{}>)>
// $ExpectType Record<"root", CSSProperties | CreateCSSProperties<{}> | PropsFunc<{}, CreateCSSProperties<{}>>>
const styles2 = createStyles({
root: () => ({
width: 1,
Expand All @@ -473,7 +473,7 @@ function forwardRefTest() {
foo: boolean;
}

// $ExpectType Record<"root", CSSProperties | CreateCSSProperties<testProps> | ((props: testProps) => CreateCSSProperties<testProps>)>
// $ExpectType Record<"root", CSSProperties | CreateCSSProperties<testProps> | PropsFunc<testProps, CreateCSSProperties<testProps>>>
const styles3 = createStyles({
root: (props: testProps) => ({
width: 1,
Expand Down

0 comments on commit 79d9099

Please sign in to comment.