-
Notifications
You must be signed in to change notification settings - Fork 12.8k
[4.1.0-beta] Incorrect method overload selected #41099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@berickson1 is there a test suite or something I can use when testing out modifications to the material-ui definitions to make sure the things I might propose don't break anything? |
Bisected to #40002 Without an isolated repro I don't see us getting to this right away - my initial attempt to distill this down into something that didn't require the material-ui definitions wasn't successful |
In the meantime I changed this /**
* `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>; to this /**
* `makeStyles` where the passed `styles` do not depend on props
*/
export default function makeStyles<Theme = DefaultTheme, ClassKey extends string = string>(
style: Styles<Theme, never, ClassKey>,
// ^^^^^
options?: Omit<WithStylesOptions<Theme>, 'withTheme'>
): (props?: any) => ClassNameMap<ClassKey>; and got the desired behavior |
What I've shared is about as far as I've gotten to be honest. I was trying to prep our client codebase for typescript 4.1 and deal with the latest set of changes and ran into this. I'm only familiar with MUI types from a usage standpoint, but I can try to distill a specific example down either this weekend or early next week. I largely wanted to get this on the radar for the TS team since MUI is a relatively popular UI component library and this introduces an (albeit unintentional) breaking change. |
I did some digging and tracked the behaviour back to 1 specific line in the material-ui .d.ts. Commenting it out fixes everything in my example (but it's still needed for some font face overrides in general).
Below is my (somewhat stream of consciousness) dive into the underlying MUI types a bit - may or may not be useful for investigations, but doesn't hurt to post A bit more info:
The problematic type in there is This is about as far as I've been able to make it today. |
The title here should be updated - this doesn't appear to be related to method overloads based on the distilled sample. It appears that inferred generics are improperly selected due to the usage of the spread operator in object declaration. |
I also ran into this issue today when I tried out the TS 4.1 RC. In case it's helpful, here's my repro. This type checks in TS 4.0.2 but not 4.1RC. import {createStyles, makeStyles} from '@material-ui/core/styles';
import React from 'react';
export function HeaderBreadcrumbs() {
const classes = useStyles();
// ~~~~~~~~~~~ Expected 1 arguments, but got 0. ts(2554)
return <div className={classes.outer}>Hello!</div>;
}
const useStyles = makeStyles(theme =>
createStyles({
outer: {
'& .MuiLink-root': {
...theme.typography.h6, // this line is key!
color: 'inherit',
},
},
}),
); |
This bug persists on |
I'm going to close this issue. The repro is quite complex and it isn't clear to me what the types are trying to achieve, plus it looks like the working cases in the repro actually rely on type inference failing and defaulting to the |
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 intomakeStyle
, 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
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:
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
The text was updated successfully, but these errors were encountered: