Emotion styled + material-ui + typescript 类型实例化过深并且可能是无限的

Nal*_*hin 3 javascript emotion typescript reactjs material-ui

我在使用样式化 API (@emotion/styled) 为从 Material-UI 库导入的组件设置样式时遇到错误。

Error:(19, 5) TS2589: Type instantiation is excessively deep and possibly infinite. 
Run Code Online (Sandbox Code Playgroud)

正如一些人所建议的那样,我尝试降级到 typescript 3.5.3,但这并没有解决问题。

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;
Run Code Online (Sandbox Code Playgroud)

Nal*_*hin 5

将通用参数设置为空对象修复了该问题。

const StyledTextField = styled(TextField)<{}>`
  margin: 10px
`;
Run Code Online (Sandbox Code Playgroud)