相关疑难解决方法(0)

打字稿输入onchange event.target.value

在我的react和typescript应用程序中,我使用:onChange={(e) => data.motto = (e.target as any).value}.

我如何正确定义类的类型,所以我不必破解我的类型系统any

export interface InputProps extends React.HTMLProps<Input> {
...

}

export class Input extends React.Component<InputProps, {}> {
}
Run Code Online (Sandbox Code Playgroud)

如果我把target: { value: string };我得到:

ERROR in [default] /react-onsenui.d.ts:87:18
Interface 'InputProps' incorrectly extends interface 'HTMLProps<Input>'.
  Types of property 'target' are incompatible.
    Type '{ value: string; }' is not assignable to type 'string'.
Run Code Online (Sandbox Code Playgroud)

types typescript reactjs typescript-typings

84
推荐指数
14
解决办法
9万
查看次数

标签 统计

reactjs ×1

types ×1

typescript ×1

typescript-typings ×1