Skip to content

Commit

Permalink
[styles] Add support for TypeScript 4.1 (#23692)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldrick committed Nov 23, 2020
1 parent 2f8b294 commit 8109926
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
16 changes: 4 additions & 12 deletions packages/material-ui-styles/src/makeStyles/makeStyles.d.ts
Expand Up @@ -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<Theme = DefaultTheme, ClassKey extends string = string>(
style: Styles<Theme, {}, ClassKey>,
options?: Omit<WithStylesOptions<Theme>, 'withTheme'>
): (props?: any) => ClassNameMap<ClassKey>;
/**
* `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<Theme, Props, ClassKey>,
options?: Omit<WithStylesOptions<Theme>, 'withTheme'>
): (props: Props) => ClassNameMap<ClassKey>;
): keyof Props extends never // `makeStyles` where the passed `styles` do not depend on props
? (props?: any) => ClassNameMap<ClassKey> // `makeStyles` where the passed `styles` do depend on props
: (props: Props) => ClassNameMap<ClassKey>;
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions packages/material-ui/src/styles/makeStyles.d.ts
Expand Up @@ -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<Theme = DefaultTheme, ClassKey extends string = string>(
style: Styles<Theme, {}, ClassKey>,
options?: Omit<WithStylesOptions<Theme>, 'withTheme'>
): (props?: any) => ClassNameMap<ClassKey>;
/**
* `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<Theme, Props, ClassKey>,
options?: Omit<WithStylesOptions<Theme>, 'withTheme'>
): (props: Props) => ClassNameMap<ClassKey>;
): keyof Props extends never // `makeStyles` where the passed `styles` do not depend on props
? (props?: any) => ClassNameMap<ClassKey> // `makeStyles` where the passed `styles` do depend on props
: (props: Props) => ClassNameMap<ClassKey>;

0 comments on commit 8109926

Please sign in to comment.