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

我只是将上面的内容作为代码放入,以便 V 部分显示出来......(而且我不知道如何搜索包含在人字形中的东西或这些东西被称为)

我已经搜索了我能想到的一切。ngrx 文档在https://v7.ngrx.io/guide/entity/interfaces的文档中使用它,我发现本教程提到了它 - https://medium.com/ngrx/introducing-ngrx-entity-598176456e15

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

这是它使用的接口:

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>?
4

1 回答 1

0

所以它使用打字稿。

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

在上面的界面中,您可以想象某些东西会使用这样的界面

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

ObjectName将是您希望用作实体或数据库实体的对象。

ids键是numberor的数组,string并且entities键本质上是键的对象(无论它们是数字还是字符串,其值为ObjectName

这是它的样子(ObjectName 是我表示对象的方式,它可以是 Todo 或 User):

{
    ids: ['1','2'],
    entities: {
        '1': {
            ...ObjectName
        }
    }
}
于 2019-07-15T05:03:59.870 回答