1. 13
    How to Apply Types to Redux Selectors
    59s

How to Apply Types to Redux Selectors

InstructorJamund Ferguson

Share this video with your friends

Send Tweet

What I've found with nearly every method provided by RTK is that type support comes really easy. This is definitely true for the createSelector method. As long as you type the state argument on your input selectors, TypeScript can calculate your return value as well as the value of the various inputs to your result function.

if you want to type the function fully you can use the following syntax:

createSelector<RootState, ResultInputType(s)..., ResultOutputType>(...)
```

---

More info about types in Redux can be found here:
https://redux.js.org/recipes/usage-with-typescript
Steve
~ 3 years ago

I'm really confused about how the number 'total.toFixed' is getting cast to a string when it reaches 'totalPrice' in Cart.tsx?

Jamund Fergusoninstructor
~ 3 years ago

Every number in JavaScript has a toFixed method which returns a the number as a string with a set number of decimal places included. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed for a thorough explanation. Does that clear things up?