0

we have routes that expect data like {"foo": "always there", "bar": "optional"}

we also have routes that send such data.

How do we handle this in redux and typescript.

Should we change the backend to return default values for optional fields or should the frontend handle these things?


When we tried it with our existing types and state management, It just gave an error whenever it encountered undefined.

  • You can use axios for it. Or you can just check this [question](https://stackoverflow.com/questions/37230555/get-with-query-string-with-fetch-in-react-native) – Barış Şahin Aug 20 '23 at 18:52
  • Generally, you write types that declare some fields as optional. You use these types by asserting that a response contains an object of a certain type. And then the same thing for redux. The question is really open as there are multiple ways to deal with this and some things are also up to the architect of your system. Are you looking to read general best practices? Then SO questions are the wrong approach unfortunately. Are you trying to solve the error you got with your existing types? Then you need to post code snippets and error messages. – timotgl Aug 21 '23 at 08:22
  • Please provide enough code so others can better understand or reproduce the problem. – Community Aug 22 '23 at 13:08

0 Answers0