Search code examples
javascriptreactjstypescriptmaterial-uiemotion

Type instantiation is excessively deep and possibly infinite with Emotion styled + material-ui + typescript


I'm getting an error while styling a component imported from the Material-UI library with styled API (@emotion/styled).

Error:(19, 5) TS2589: Type instantiation is excessively deep and possibly infinite. 

I've tried downgrading to typescript 3.5.3, as some people suggested, but that didn't fix the issue.

import * as React from 'react';
import styled from '@emotion/styled';
import TextField from '@material-ui/core/TextField';


const StyledTextField = styled(TextField)`
  margin:10px;
`;

interface InputProps {
  value: string;
  name: string;
  label: string;
  onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
}

const Input: React.FC<InputProps> = ({ value, name, label, onChange }) => {
  return (
    <StyledTextField
      value={value}
      name={name}
      onChange={onChange}
      label={label}
    />
  );
};

export default Input;

Solution

  • Setting a generic argument as an empty object fixed the issue.

    const StyledTextField = styled(TextField)<{}>`
      margin: 10px
    `;