javascript – combineLatest<{ [id: string]: Book }, string[]> What is this?

javascript – combineLatest<{ [id: string]: Book }, string[]> What is this?

The line <{ [id: string]: Book }, string[]> is so called diamond notation. It means that the function combineLatest takes arguments of a generic type that you define within the diamonds.

So it means take an object with a string key and a value of type Book as first parameter and as second parameter, take an array of string values

The parameters:

(state$.let(getBookEntities),state$.let(getSearchBookIds)

The first parameter is supposed to be of type { [id: string]: Book } and the second parameter must be of type array[].

The general syntax is like:

function identity<T>(arg: T): T {
  return arg;
}

The function identity is of any type T, takes an argument of type T and returns T.

A sample usage could look like that:

var foo = identity<string>(hello);

The function identity takes a parameter of string, because you defined it to be string, but you could reuse this function for any type you specify there. it has a return type of string and just returns the passed argument, which is hello.

(Also see https://www.typescriptlang.org/docs/handbook/generics.html)

This hopefully helped you understanding.

It is the same as the generic types in Java.

javascript – combineLatest<{ [id: string]: Book }, string[]> What is this?

Leave a Reply

Your email address will not be published. Required fields are marked *