From 7d9e5a2d674bb2c52cf4da5df1220afe5937a550 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 4 Mar 2020 18:30:47 -0800 Subject: [PATCH 1/3] packages Name anonymous function type ...to speed up compilation (by simplifying structural type comparison). Note that, in most cases, the performance benefit of extracting a name type will be insignificant. --- packages/material-ui-styles/src/withStyles/withStyles.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/material-ui-styles/src/withStyles/withStyles.d.ts b/packages/material-ui-styles/src/withStyles/withStyles.d.ts index 3bd02d7900e150..2a20e606102312 100644 --- a/packages/material-ui-styles/src/withStyles/withStyles.d.ts +++ b/packages/material-ui-styles/src/withStyles/withStyles.d.ts @@ -9,6 +9,8 @@ export {}; type JSSFontface = CSS.FontFace & { fallbacks?: CSS.FontFace[] }; +type PropsFunc = (props: Props) => T; + /** * Allows the user to augment the properties available */ @@ -29,7 +31,7 @@ export interface CSSProperties extends BaseCSSProperties { } export type BaseCreateCSSProperties = { - [P in keyof BaseCSSProperties]: BaseCSSProperties[P] | ((props: Props) => BaseCSSProperties[P]) + [P in keyof BaseCSSProperties]: BaseCSSProperties[P] | PropsFunc }; export interface CreateCSSProperties @@ -55,7 +57,7 @@ export type StyleRules // JSS property bag based on props - | ((props: Props) => CreateCSSProperties) + | PropsFunc> >; /** From b7559ed3ef86b90780f53ee53a59649cc1f7b677 Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Wed, 4 Mar 2020 18:39:25 -0800 Subject: [PATCH 2/3] Add missing type parameter constraint --- packages/material-ui-styles/src/withStyles/withStyles.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/material-ui-styles/src/withStyles/withStyles.d.ts b/packages/material-ui-styles/src/withStyles/withStyles.d.ts index 2a20e606102312..9cfe360fe6640c 100644 --- a/packages/material-ui-styles/src/withStyles/withStyles.d.ts +++ b/packages/material-ui-styles/src/withStyles/withStyles.d.ts @@ -9,7 +9,7 @@ export {}; type JSSFontface = CSS.FontFace & { fallbacks?: CSS.FontFace[] }; -type PropsFunc = (props: Props) => T; +type PropsFunc = (props: Props) => T; /** * Allows the user to augment the properties available From 82b88330f9c109ce450bbf97a59864e4ead1141b Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 5 Mar 2020 11:39:43 +0100 Subject: [PATCH 3/3] fix snapshot tests --- packages/material-ui-styles/test/styles.spec.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/material-ui-styles/test/styles.spec.tsx b/packages/material-ui-styles/test/styles.spec.tsx index 03bcc37a288ab6..0219868b3d838b 100644 --- a/packages/material-ui-styles/test/styles.spec.tsx +++ b/packages/material-ui-styles/test/styles.spec.tsx @@ -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, @@ -473,7 +473,7 @@ function forwardRefTest() { foo: boolean; } - // $ExpectType Record<"root", CSSProperties | CreateCSSProperties | ((props: testProps) => CreateCSSProperties)> + // $ExpectType Record<"root", CSSProperties | CreateCSSProperties | PropsFunc>> const styles3 = createStyles({ root: (props: testProps) => ({ width: 1,