我想解释我传递给Typescript组件的props。这些是我的道具:
export type IssueListHomeProps = {
projects: ProjectDtoImpl[];
issues: IssueDtoImpl[];
timeEntries: TimeEntryDtoImpl[];
handleRefresh: () => void;
changeMode: (m: string) => void;
selectTimeEntry: (entry: TimeEntryDtoImpl) => void;
pullToRefresh: boolean;
dates: string[];
} & RouteComponentProps;
这就是我要这样做的方式:
const {projects: ProjectDtoImpl[], issues: IssueDtoImpl[],timeEntries: TimeEntryDtoImpl[],pullToRefresh: boolean, dates: string[]} = this.props
但是我收到类似这样的错误:
1.Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
2.Expression expected
我不知道在哪里执行此操作:在组件中还是在外部,或者可能在构造函数中?在此先感谢!
嗯,在销毁中使用类型是不正确的;正确的制作方法是这样的:
render() {
const {
projects,
issues,
timeEntries,
pullToRefresh,
dates
}: IssueListHomeProps = this.props;