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.

No overload matches styled

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

From the example https://mui.com/components/app-bar/ Screenshot_theme_mixins

import { styled } from '@mui/material/styles';
const Offset = styled('div')(({ theme }) => theme.mixins.toolbar);
No overload matches this call.
  The last overload gave the following error.
    Argument of type '({ theme }: MUIStyledCommonProps<Theme> & ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & { ...; }) => CSSProperties' is not assignable to parameter of type 'TemplateStringsArray'.
      Type '({ theme }: MUIStyledCommonProps<Theme> & ClassAttributes<HTMLDivElement> & HTMLAttributes<HTMLDivElement> & { ...; }) => CSSProperties' is missing the following properties from type 'TemplateStringsArray': raw, concat, join, slice, and 9 more.ts(2769)
index.d.ts(117, 3): The last overload is declared here.

Expected behavior 🤔

Typescript should not throw error

Steps to reproduce 🕹

  1. const Offset = styled(‘div’)(({ theme }) => theme.mixins.toolbar);

Context 🔦

No response

Your environment 🌎

`npx @mui/envinfo` System: OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa) CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz Memory: 172.19 MB / 15.50 GB Container: Yes Shell: 5.8 - /usr/bin/zsh Binaries: Node: 16.9.1 - ~/.nvm/versions/node/v16.9.1/bin/node Yarn: 1.22.17 - ~/.yarn/bin/yarn npm: 7.23.0 - ~/.nvm/versions/node/v16.9.1/bin/npm Managers: Apt: 2.0.6 - /usr/bin/apt Cargo: 1.57.0 - ~/.cargo/bin/cargo pip2: 9.0.1 - /usr/local/bin/pip2 pip3: 20.1.1 - ~/anaconda3/bin/pip3 RubyGems: 3.1.2 - /usr/bin/gem Utilities: CMake: 3.16.3 - /usr/bin/cmake Make: 4.2.1 - /usr/bin/make GCC: 9.3.0 - /usr/bin/gcc Git: 2.25.1 - /usr/bin/git Clang: 10.0.0 - /usr/bin/clang Ninja: 1.10.0 - /usr/bin/ninja Mercurial: 5.3.1 - /usr/bin/hg FFmpeg: 4.2.4 - /usr/bin/ffmpeg Virtualization: Docker: 20.10.12 - /usr/bin/docker VirtualBox: 6.1.26 - /usr/bin/vboxmanage IDEs: Android Studio: 3.6 AI-192.7142.36.36.6241897 Nano: 4.8 - /bin/nano Sublime Text: 4125 - /usr/bin/subl VSCode: 1.63.2 - /usr/bin/code Vim: 8.1 - /usr/bin/vim Languages: Bash: 5.0.17 - /bin/bash Perl: 5.30.0 - /usr/bin/perl Python: 3.8.3 - /home/someone/anaconda3/bin/python Python3: 3.8.3 - /home/someone/anaconda3/bin/python3 Ruby: 2.7.0 - /usr/bin/ruby Rust: 1.57.0 - /home/someone/.cargo/bin/rustc Databases: SQLite: 3.32.3 - /home/someone/anaconda3/bin/sqlite3 Browsers: Chrome: 97.0.4692.71 Firefox: 95.0.1
{
  "extends": "../../tsconfig.json",
  "lib": ["dom", "ESNext"],
  "include": [
    "./src/**/*",
    "./custom.d.ts"
  ]
}
{
  "extends": "./tsconfig.build.json",
  "compilerOptions": {
    "baseUrl": ".",
    "jsx": "react",
    "esModuleInterop": true,
    "noEmit": true
  },
  "exclude": [
    "node_modules"
  ]
}

tsconfig.build.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true,
    "noEmitOnError": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "types": [],
    "jsx": "react",
  },
  "lib": ["dom", "ESNext"],
  "include": [
    "./custom.d.ts"
  ],
  "exclude": [
    "node_modules",
    "dist",
    "build"
  ]
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
vanduc1102commented, May 15, 2022

it is caused of

  ...theme.mixins.toolbar,

According to this: https://stackoverflow.com/a/53329367/1681903

We can use:

 const DrawerHeader = styled('div')(({ theme }) => ({
  display: 'flex',
  alignItems: 'center',
  justifyContent: 'flex-end',
  padding: theme.spacing(0, 1),
  // necessary for content to be below app bar
minHeight: '64px',
}));
1reaction
dohomicommented, Jun 2, 2022

I think this is a permanent issue also with newest TypeScript versions. I ran into this issue with using a bought theme of minimal.cc.

export const ListSubheaderStyle = styled((props) => (
  <ListSubheader disableSticky disableGutters {...props} />
))(({ theme }) => ({
  paddingTop: theme.spacing(3),
  paddingLeft: theme.spacing(2),
  paddingBottom: theme.spacing(1),
  color: theme.palette.text.primary,
  transition: theme.transitions.create('opacity', {
    duration: theme.transitions.duration.shorter
  }),
  ...theme.typography.overline
}))

My workaround to fix it is a type cast:

export const ListSubheaderStyle = styled((props) => (
  <ListSubheader disableSticky disableGutters {...props} />
))(({ theme }) => ({
  paddingTop: theme.spacing(3),
  paddingLeft: theme.spacing(2),
  paddingBottom: theme.spacing(1),
  color: theme.palette.text.primary,
  transition: theme.transitions.create('opacity', {
    duration: theme.transitions.duration.shorter
  }),
  ...theme.typography.overline as any // this causing the TS error
}))
Read more comments on GitHub >

github_iconTop Results From Across the Web

No overload matches this call when usign styled-components
When using a Styled component inside another component and passing props to it, do I have to create a new type to pass...
Read more >
No overload matches this call with styled components ...
No overload matches this call in TypeScript is really annoying and there aren't too many solutions around there, though we have a solution!...
Read more >
[styled-components] No overload matches this call for attrs ...
I got the No overload matches this call error in a similar scenario and have a workaround. What I encountered. I defined a...
Read more >
Styled-component type error. : r/reactjs - Reddit
It is very frustrating because it is causing my builds to fail. Here's the error: No overload matches this call. Overload 1 of...
Read more >
[Solved]-Error on styled component instance with TypeScript
Coding example for the question Error on styled component instance with TypeScript: No overload matches this call-Reactjs.
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