我有我的应用程序根目录和一个延迟加载的组件。
App root:
import Component from './app/components/component/component.lazy';
class App extends React.Component{
stuff: stuffType[] = [1, 2 , 3];
render() {
return (
<Component stuff={this.stuff}/>
);
}
}
export default App;
惰性组件:
import React, { lazy, Suspense } from 'react';
import {stuffType} from '../../dto/types';
const Lazycomponent = lazy(() => import('./component'));
const component = (props: {tanks: stuffType[]} & { children?: React.ReactNode; }) => (
<Suspense fallback={null}>
<Lazycomponent {...props} />
</Suspense>
);
export default component;
Component:
const component: React.FC<any> = (stuff: stuffType[]) => {
return(
{stuff.map((stuff: stuffType, index: number) => {
return (
<div >
</div>
)
})}
)
}
上面的代码在实时类型检查之后以及在运行控制台中都没有错误。
但是在浏览器中运行时,我得到的错误是>>
TypeError:stuff.map不是函数
好很好:
const component: React.FC<stuffType[]> = (stuff: stuffType[]) => {
现在不进行实时类型检查在惰性组件中失败:
TS2740:类型'{stuff:stuffType [];孩子们?:ReactNode; }'是类型'stuffType []'缺少以下属性:length,pop,推,连击以及另外28个。
当我给它的是数组时,怎么说呢?
我有我的应用程序根目录和一个延迟加载的组件。应用根目录:从“ ./app/components/component/component.lazy”导入组件; App类扩展了React.Component {stuff:stuffType [] = [1,2,3]; ...
道具是对象而不是数组。