使用打字稿破坏道具

问题描述 投票:0回答:1

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

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

reactjs typescript
1个回答
0
投票

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

render() {
    const {
      projects,
      issues,
      timeEntries,
      pullToRefresh,
      dates
    }: IssueListHomeProps = this.props;
© www.soinside.com 2019 - 2024. All rights reserved.