[4.1.0-beta] Incorrect method overload selected
See original GitHub issueRelevant 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:
https://github.com/microsoft/TypeScript/issues/41049 <- Looks similar but only relates to promises, so is not applicable here
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top GitHub Comments
After a short delay, I have a contrived standalone repro. I’ve updated the git repo above and created a playground link: https://www.typescriptlang.org/play?#code/C4TwDgpgBAUgynAYgewHbAGYEMDG0C8UA3gFBRQ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