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)
将通用参数设置为空对象修复了该问题。
const StyledTextField = styled(TextField)<{}>`
margin: 10px
`;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2277 次 |
| 最近记录: |