Search code examples
typescriptngrxngrx-entity

In ngrx entity please tell me what type <V> is in EntityState<V>


I just want to find what this type <V> for EntityState<V> is.

I just put the above in as code so that the V part shows up...( and I have no freaking idea how to search for something that is enclosed in chevrons or wtf those things are called)

I've searched for everything I can think of. The ngrx docs use it in the documentation for https://v7.ngrx.io/guide/entity/interfaces and I found this tutorial that mentions it - https://medium.com/ngrx/introducing-ngrx-entity-598176456e15

... but I just can't figure out what is type <V>.

Here is the interface it is used in:

interface EntityState<V> {
  ids: string[] | number[];
  entities: { [id: string | id: number]: V };
}

This probably sounds retarded but HOW do I figure out the answer 
to this seemingly incredibly simple question?  What is <V>?

Solution

  • So it is using typescript.

    interface EntityState<V> {
      ids: string[] | number[];
      entities: { [id: string | id: number]: V };
    }
    

    in the above interface you can picture that something would use the interface like this

    class AnyClassname implements EntityState<ObjectName>{ ... }
    

    ObjectName would be the object you want used as an entity or database entity.

    the ids key is an array of either number or string and the entities key is essentially an object of the key (whether they are numbers or string with a value of ObjectName

    Here is what it could look like (ObjectName is how I am representing an object, it could be a Todo or a User):

    {
        ids: ['1','2'],
        entities: {
            '1': {
                ...ObjectName
            }
        }
    }