繁体   English   中英

重构对Typecript的反应会导致错误属性'readOnly'在类型'IntrinsicAttributes&InputProps&{children?:ReactNode; }”

[英]Refactoring React to Typescript causes error Property 'readOnly' does not exist on type 'IntrinsicAttributes & InputProps & { children?: ReactNode; }'

我正在使用Typescript重构一个应用程序。 除了这个简单的组件外,Everthing的进展顺利。 我正在使用来自material-ui Input

import {Input} from "material-ui";

class Cp extends React.Component<any, any> {
    render = () => <Input readOnly/>          
}

Typescript编译器抱怨readOnly属性,但它在JavaScript中运行良好。

TS2559: Type '{ readOnly: true; }' has no properties in common with type 'IntrinsicAttributes & InputProps & { children?: ReactNode; }'.

但是我可以在由Input元素的props扩展的接口HTMLInputElement看到属性readOnly

如何绕过这个错误?

readOnly不是输入组件的道具。 你试过这种方式吗?

<Input inputProps={{ readOnly: true }} />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM