angularngrxcode-documentationmethod-signaturetechnical-debt

How do I read or interpret the Angular ngrx documentation correctly?


I have the createAction function from ngrx.io Store... with that signature: https://v11.ngrx.io/api/store/createAction

createAction<T extends string, C extends Creator>(type: T, config?: C | { _as: "props"; }): ActionCreator<T>

and this:

createAction(type: T, config: ActionCreatorProps<P> & NotAllowedCheck<P>): ActionCreator<T, (props: P & NotAllowedCheck<P>) => P & TypedAction<T>>

Creator typpe itself has that signature:

type Creator<P extends any[] = any[], R extends object = object> = FunctionWithParametersType<P, R>;

I really have problems reading this, e.g what means config?: C | { _as: "props";} is it an optional config property with type C or object { _as: "props";} ? Can someone help me debunk one of those above syntaxes? And btw, the documentations are generally also written in the same language, is that right? so a doc about flutter would have its flutter signatures for methods, etc. right?


Solution

  • This is how I read it.

    So this means I can't define my myCreateAction with string and object because object doesn't extend Creator. This is a way of limiting what you can pass into an implementation of createAction.

    Let's continue.

    So basically, what's happening is we're defining the signature of a function: its name, acceptable parameters and return type.

    The same goes for the second function you mention:

    So, let's say you use this createAction with T being a string and P being a MyAction (not sure if this is realistic, I have no NgRx experience). The createAction call would return an ActionCreator<string, (props: MyAction & NotAllowedCheck<MyAction>). This ActionCreator will in turn return a MyAction & TypedAction<string> object.

    Finally, the last statement works the same way: