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

Viewed 5440

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;
3 Answers

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

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

Following on from Nalhin's response, this is the correct type definition, of TextFieldProps.

const StyledTextField = styled(TextField)<TextFieldProps>`
  margin:10px;
`;
Related