【发布时间】:2019-08-16 03:35:39
【问题描述】:
我有一个 JSX 类的打字稿代码
export class SearchForm extends React.PureComponent<Props, State> {
public inputRef: React.RefObject<{}>;
constructor(props: any) {
super(props)
this.inputRef = React.createRef()
}
public componentDidMount(): void {
this.inputRef.current.focus()
this.inputRef.current.select()
...
现在当我尝试编译这段代码时,我遇到了一堆错误:
ERROR in ...
TS2339: Property 'className' does not exist on type '{}'.
ERROR in ...
TS2339: Property 'focus' does not exist on type '{}'.
什么是问题?
【问题讨论】:
-
另一种选择是
this.inputRef = React.createRef<HTMLInputElement | null>(null)...
标签: reactjs typescript typescript-typings typescript2.0