question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[4.1.0-beta] Incorrect method overload selected

See original GitHub issue

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: https://github.com/microsoft/TypeScript/issues/41049 <- Looks similar but only relates to promises, so is not applicable here

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
berickson1commented, Oct 26, 2020

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/C4TwDgpgBAUgynAYgewHbAGYEMDG0C8UA3gFBRQD0AVFAM7IC20YATspC8AJYS1QAWEFhAA0UACbJeUVMmBQGWYMCFQMyFlGFhkUKhRIBfANwkSoSFAAKbMLUQBXVDgA8N9nwgAPFanF9kACMAKwgcYDEAFQA+KEIAClYPAC5rW1oASjjYyNMSaioyGgBBABtS5AB3PmBBKAdaVWBdLAcAcyZ0KFrmWyFuaSwANywuUqxA0ogigy50IWw8KDghtvcOAdoXSIAZCFQ22rioeNpgFjm2qAAyYkMsgB8oAAZY0nJArEbSuYg4fi4GGAAH5Urt9od+KZyBgxioWKC6OdLjc7qZDCRvDpOFA5vDFtB1v0eFtwQcjgkzhcDqiiPcoE9XmQoN5fP5lqsiZwSds9uT+G8MSQ8QtcNAAEJfCAAYQQXM2LJ8+3Z8p5qAcDECqieVMub2ZFAoADkAPKRACiqQAkhhugC+Fw+MEGvJ1ZqhGIeoqsAwwFMoDhGGAxrwDRQAOQAAXU6AAtATw4j4Eg0JgxQzYAgUOgCQBtAC60O6vBBqWT2bTeAL6LMIpYBKgsrgqukrOVfEljSbLb470oFCgZQqlSgdggDkkdAgU3CGj4WD8Cgg4i4WCgAEcHEISWGoAADJwAa1klVQe9xfAay7ocyWkTgEikfFk8iw5SqUC+tC4bVQKIXuLzPW6aVFwtTIA4wC7gBcziN4N6-koDjCN0uhoNAoFHDBfjwd+iHAMhEAAHRQJE9oXqhn7viOFjQLQWAYNM5CGgoyDiA4-qtB0+zAEoXBoERu6RGE-B-jgb6lCAUCVBhC6vqgUmHhAUkvt04DXnM+6djKcp9NyvDns0UBalAyC2rRu57t2embOegSQXajqPrwqDhvIlQaIeJFkdAsG4T+qBIShqAQMuNS6IGQxCLu2nWewxKDHwMnlCRACq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wxhTEKpIU8ag2AMGIYdUoCgjoXF6Q4LgRUICxnEo0PeUT5BYlusuO+ozUi0WJjEuJBwAGEB-sgP+d9IkHxxV4SA4R8XtyUUS9SJKFHkoSYQUl8TqFKNMEAA

0reactions
timbuckleycommented, Nov 20, 2020

This bug persists on 4.1.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect overloaded method selected - Camunda Forum
Faced the following problem. In my service bean I have 2 overloaded methods: public Application doSmth(final Long applicationId) { //logic }
Read more >
2.48. Version 4.1.0 Beta 1 - Documentation
Fixed AUT crashes on exit on macOS. Added a castToQObject overload that accepts a QObject and down-casts it to the most-derived type. Safer...
Read more >
Changelog for Groovy 3.0.0
VerifyError when initializing object of inner class within the constructor of its containing class; [GROOVY-7647] - Incorrect line information for debug ...
Read more >
c# - Why is the compiler choosing the wrong method overload?
CacheDelegate(obj, methodInfo); to force the call you want, since the base type has only one CacheDelegate overload to choose between.
Read more >
What's new in Unity 2018.3.0 Beta 7
Additional downloads Select the runtime platforms of your choice from ... Animation: Allow a function with overloads to be assigned to an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found