1

I want to desctruct react props that I pass to component with Typescript. These are my 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;

That's how I'm trying to do this:

const {projects: ProjectDtoImpl[], issues: IssueDtoImpl[],timeEntries: TimeEntryDtoImpl[],pullToRefresh: boolean, dates: string[]} = this.props

But I get errors like these:

1.Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
2.Expression expected

I don't know where to do this: in component or outside, or may be in the constructor? Thanks in Advance!!

1
  • What Element is the error talking about? As for the second error, you probably have missing colon, comma, or semicolon somewhere. Have you tried destructuring your props without indicating their type? They should implicitly have a type by this point. const {projects, issues, timeEntries, pullToRefresh, dates} = this.props Commented Mar 17, 2020 at 9:18

1 Answer 1

2

Well, It is incorrect to use types in destruction; The correct way is to make it like this:

render() {
    const {
      projects,
      issues,
      timeEntries,
      pullToRefresh,
      dates
    }: IssueListHomeProps = this.props;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.