使用Typescript破坏反应道具

时间:2020-03-17 09:07:15

标签: reactjs typescript

我想解释我传递给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

我不知道该在哪里执行:是在组件中还是在外部,或者可能在构造函数中? 在此先感谢!

1 个答案:

答案 0 :(得分:1)

嗯,在销毁中使用类型是不正确的;正确的方法是使它像这样:

render() {
    const {
      projects,
      issues,
      timeEntries,
      pullToRefresh,
      dates
    }: IssueListHomeProps = this.props;