0

I'm trying to add types to the destructured variables however they are still returning any.

Questions: How can I add types while destructing?

  export interface TableReturnState {
    status: number;
    data: APIOrders[];
    columns: [] | JSX.Element[];
    sort: Function;
  }

  const { data, sort, columns, status }: TableReturnState = useTableHook(
    configuration
  );

2 Answers 2

1

Because that's not the way to do it.

You don't decide what useTableHook returns, it's on the useTableHook to say what it returns. Destructured items will then have their correct typings.

Something like this :

useTableHook = (configuration: Configuration): TableReturnState => ...
Sign up to request clarification or add additional context in comments.

Comments

1

Your example works fine for me.
But you can try:

interface TableReturnState {
  status: number;
  data: APIOrders[];
  columns: [] | JSX.Element[];
  sort: Function;
}

function useTableHook(config: TypeOfConfig): TableReturnState {
  // Your code
}

const { data, sort, columns, status } = useTableHook(configuration);

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.