【发布时间】:2020-02-24 11:45:47
【问题描述】:
我正在调试一个我没有编写的代码,而且我是 typescript 的新手。我收到 TS2339 错误
类型“{}”上不存在属性“InputFiles”。
我明白这意味着我错过了移交财产, 但我应该修改什么?
在UI\src\containers\FileUploaderContainer.tsx 内,我有类似的东西
export class FileUploader extends React.Component<any, any> {
render() {
return ( <div><UploadFileFormContainer /></div> );
}
}
const FileUploaderContainer: { any } = connect(
state => ({ InputFiles: state.InputFiles }), // error occurs here
dispatch => ({})
)(FileUploader);
export default FileUploaderContainer;
背景
如果我将鼠标悬停在 connect 上方的 Visual Studio 中,我会看到
(alias) connect<{InputFiles: any;}, any, {}, {}>(mapStateToProps: MapStateToPropsParam<{
InputFIles: any; }, {}, {}>, mapDispatchToProps: MapDispatchToPropsNonObject<any,{}>):
InterferableComponentEnhancerWithPropos<any,{}> (+ 14 overloads)
import connect
相关问题
以下问题没有帮助我解决我的问题
- Typescript property does not exist on type {}
- Property 'xxx' does not exist on type '{}'
- property 'update' does not exist on type '{}'
- Property 'xxxx' does not exist on type '{ [key: string]: AbstractControl; }'
- How to resolve 'calls' does not exist on type '() => any'
- Property 'keys' does not exist on type 'any[]'
- Property does not exists on type '{}' using Promises
【问题讨论】:
-
好吧,你的
state(不知何故)被定义为{},所以TS不知道它的任何属性。 -
@VLAZ 你能这么好心并在这里指导我吗?我假设我应该替换
any之一?我还是不太习惯spread operator... -
@Pac0 请您详细说明一下好吗?你的意思是我应该在最后添加一个
as any? -
connect 函数的第一个参数的类型定义是什么?
标签: reactjs typescript