S
S
SHUPILOID2020-01-03 22:27:30
typescript
SHUPILOID, 2020-01-03 22:27:30

How to correctly describe a type in typesctipt?

I just can’t understand why it’s impossible to destructure the action parameter in the reducer
Without destructuring, everything works as it should, as soon as I try, errors from the typescript immediately appear that there is no such property

Here is the code with destructuring
5ff21a461ba7a841404379.png

Here is the code without
5ff21a80250b0180693585.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-01-03
@bingo347

The thing is that the profileActionsType type is a discriminated union
The post field is present in only one of its subtypes, so extracting this field from the full type is an error from the point of view of typescript.
Checking for a specific value in the type field is fine as a type guard , which ts will understand.
PS Posting code with pictures is prohibited by the rules of the service

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question