From 81099268bc2e83139a5563172ce8ad97b3397397 Mon Sep 17 00:00:00 2001 From: Ricky Lippmann <3674067+ldrick@users.noreply.github.com> Date: Mon, 23 Nov 2020 20:52:11 +0100 Subject: [PATCH] [styles] Add support for TypeScript 4.1 (#23692) --- package.json | 2 +- .../src/makeStyles/makeStyles.d.ts | 16 ++++------------ .../src/makeStyles/makeStyles.spec.tsx | 2 +- packages/material-ui/src/styles/makeStyles.d.ts | 16 ++++------------ 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index ee21aae3c15b6a..a12403a17b0458 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "test:umd": "node packages/material-ui/test/umd/run.js", "test:unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.js' 'docs/**/*.test.js' 'scripts/**/*.test.js' --exclude '**/node_modules/**'", "test:watch": "yarn test:unit --watch", - "typescript": "lerna run typescript --parallel" + "typescript": "lerna run --no-bail --parallel typescript" }, "devDependencies": { "@babel/cli": "^7.10.1", diff --git a/packages/material-ui-styles/src/makeStyles/makeStyles.d.ts b/packages/material-ui-styles/src/makeStyles/makeStyles.d.ts index f1ffc3d4b23055..e80da05cc5efa5 100644 --- a/packages/material-ui-styles/src/makeStyles/makeStyles.d.ts +++ b/packages/material-ui-styles/src/makeStyles/makeStyles.d.ts @@ -7,21 +7,13 @@ import { import { Omit } from '@material-ui/types'; import { DefaultTheme } from '../defaultTheme'; -/** - * `makeStyles` where the passed `styles` do not depend on props - */ -export default function makeStyles( - style: Styles, - options?: Omit, 'withTheme'> -): (props?: any) => ClassNameMap; -/** - * `makeStyles` where the passed `styles` do depend on props - */ export default function makeStyles< Theme = DefaultTheme, - Props extends {} = {}, + Props extends object = {}, ClassKey extends string = string >( styles: Styles, options?: Omit, 'withTheme'> -): (props: Props) => ClassNameMap; +): keyof Props extends never // `makeStyles` where the passed `styles` do not depend on props + ? (props?: any) => ClassNameMap // `makeStyles` where the passed `styles` do depend on props + : (props: Props) => ClassNameMap; diff --git a/packages/material-ui-styles/src/makeStyles/makeStyles.spec.tsx b/packages/material-ui-styles/src/makeStyles/makeStyles.spec.tsx index 3e254c40713795..d423f06a2dd296 100644 --- a/packages/material-ui-styles/src/makeStyles/makeStyles.spec.tsx +++ b/packages/material-ui-styles/src/makeStyles/makeStyles.spec.tsx @@ -81,7 +81,7 @@ import { createStyles, makeStyles } from '@material-ui/styles'; ); const UnsafeProps = (props: StyleProps) => { - // would be nice to have at least a compile time error because we forgot the argument + // @ts-expect-error const classes = useUnsafeProps(); // runtime: Can't read property color of undefined // but this would pass anyway const alsoClasses = useUnsafeProps(undefined); // runtime: Can't read property color of undefined diff --git a/packages/material-ui/src/styles/makeStyles.d.ts b/packages/material-ui/src/styles/makeStyles.d.ts index 0581923403e100..d99482431fa5de 100644 --- a/packages/material-ui/src/styles/makeStyles.d.ts +++ b/packages/material-ui/src/styles/makeStyles.d.ts @@ -3,21 +3,13 @@ import { ClassNameMap, Styles, WithStylesOptions } from '@material-ui/styles/wit import { Omit } from '@material-ui/types'; -/** - * `makeStyles` where the passed `styles` do not depend on props - */ -export default function makeStyles( - style: Styles, - options?: Omit, 'withTheme'> -): (props?: any) => ClassNameMap; -/** - * `makeStyles` where the passed `styles` do depend on props - */ export default function makeStyles< Theme = DefaultTheme, - Props extends {} = {}, + Props extends object = {}, ClassKey extends string = string >( styles: Styles, options?: Omit, 'withTheme'> -): (props: Props) => ClassNameMap; +): keyof Props extends never // `makeStyles` where the passed `styles` do not depend on props + ? (props?: any) => ClassNameMap // `makeStyles` where the passed `styles` do depend on props + : (props: Props) => ClassNameMap;