Description
Relevant investigation data:
Material UI makeStyle
function has 2 signatures, 1 where Props are empty object ({}
), the second where props are a generic (default of {}
). When using the spread operator for the object passed into makeStyle
, the second more specific (and incorrect) signature is picked. This ONLY happens when there are other values provided before or after the spread operator. If the spread object is the only set of values in the object, the 'correct' overload is suggested.
I believe all 3 cases below should be equivalent and select the same function overload. This works perfectly in previous versions of typescript, so would indicate some form of bug or un-tracked breaking change.
TypeScript Version: 4.1.0-beta & 4.1.0-dev.20201014
Search Terms:
Material UI styles TS2554 overload type
Code
const useStylesBroken = makeStyles(theme =>
createStyles({
sizeSmall: {
...theme.typography.button, // This is simply a set of css styles - nothing relating to props
height: '36px',
},
})
);
const useStylesWorks = makeStyles(theme =>
createStyles({
sizeSmall: {
height: '36px',
},
})
);
const useStylesWorks2 = makeStyles(theme =>
createStyles({
sizeSmall: {
...theme.typography.button,
},
})
);
export function NotReallyAButton(): null {
console.log(useStylesBroken());
console.log(useStylesWorks());
console.log(useStylesWorks2());
return null
}
See https://github.com/berickson1/Playground/blob/master/materialUiSample.ts
Expected behavior:
Code compiles successfully (as in previous released typescript versions)
Actual behavior:
Incorrect overload chosen & compiler error:
materialUiSample.ts:27:17 - error TS2554: Expected 1 arguments, but got 0.
27 console.log(useStylesBroken());
~~~~~~~~~~~~~~~~~
node_modules/@material-ui/core/styles/makeStyles.d.ts:23:5
23 ): (props: Props) => ClassNameMap<ClassKey>;
~~~~~~~~~~~~
An argument for 'props' was not provided.
Playground Link:
Requires material-ui dependency installed, see repo at https://github.com/berickson1/Playground (yarn install && yarn build
)
Related Issues:
#41049 <- Looks similar but only relates to promises, so is not applicable here