2

Please be kind, if this question is very naive.

When working with redux the function createStore confused me a little. The function has three arguments:

createStore(reducer, preloadedState, enhancer)

Yet calling createStore like this also works with no problems:

createStore(reducer, enhancer)

This leads me to believe that the sequence of arguments does not really matter here. Does redux only check for the type of the arguments and then assign it to the right property. I looked in the source code, but since it is TypeScript I have a bit of a hard time understanding this.

How does this work?

Xen_mar
  • 8,330
  • 11
  • 51
  • 74
  • 1
    Sequence does matters. What you are looking at is called `Function Overloading`. A function can have multiple signature and based on the arguments, best matching function is called – Rajesh Sep 19 '19 at 08:22
  • I add something more. Types don't exist at runtime, it's just something made up for code linting. In these scenarios, the check can be only made on the number of arguments, not on the type. – Christian Vincenzo Traina Sep 19 '19 at 15:25

0 Answers0