Skip to content

how to handle multiple return type in action in typescript #5369

Closed Answered by machour
tomer-yechiel asked this question in Q&A
Discussion options

You must be logged in to vote

Since you're returning two different structures, TypeScript needs you to test things for yourself:

  if (actionData && "baz" in actionData) {
      console.log(actionData.baz); // TypeScript is happy here
  }

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@tomer-yechiel
Comment options

@machour
Comment options

Answer selected by tomer-yechiel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants