我在通过演示React项目工作时遇到问题。大多数 问题源于我试图在使用Javascript的Typescript中实现它的问题。要点是我的app.tsx文件。
https://gist.github.com/jjuel/59eed01cccca0a7b4f486181f2a14c6c
运行此命令时,出现与接口有关的错误。
./app/app.tsx中的错误(38,17):错误TS2324: 类型’IntrinsicAttributes&IntrinsicClassAttributes&AppProps&{ children ?: ReactElement |…’中缺少属性’humans ‘。 ./app/app.tsx(38,17)中的错误:错误TS2324: 类型’IntrinsicAttributes&IntrinsicClassAttributes&AppProps&{ children ?: ReactElement |…’中缺少属性’stores ‘。webpack:捆绑包现在有效。
./app/app.tsx中的错误(38,17):错误TS2324: 类型’IntrinsicAttributes&IntrinsicClassAttributes&AppProps&{ children ?: ReactElement |…’中缺少属性’humans ‘。
./app/app.tsx(38,17)中的错误:错误TS2324: 类型’IntrinsicAttributes&IntrinsicClassAttributes&AppProps&{ children ?: ReactElement |…’中缺少属性’stores ‘。webpack:捆绑包现在有效。
我不知道这是怎么回事。有人知道我的问题 是什么吗?谢谢!
You have the following interface :
interface AppProps { humans: any; stores: any; }
但是要初始化它<App />在ReactDOM.render(<App />, document.getElementById('main')); 没有属性。这是TypeScript,可为您提供有关您所说的预期用途的错误。这是一个错误,例如具有带参数的函数但在不传递任何参数的情况下调用它。
<App />
ReactDOM.render(<App />
document.getElementById('main'))
TypeScript
固定 也许这些属性对您来说是可选的?如果是这样声明的话:
interface AppProps { humans?: any; stores?: any; }
否则,请提供它们<App humans={123} stores={123} />(例如,人员和商店的示例实例)。
<App humans={123} stores={123} />