Reputation: 493
I'm using d3 with typescript and there is a lot of types in d3 that are like this SomeType<U,T,V>
. Example:
merge(other: Selection<GElement, Datum, PElement, PDatum>): Selection<GElement, Datum, PElement, PDatum>
I looked through the advanced types documentation but could not understand what these types mean. I can't say if they are a Selection type with these subtypes or whatever.
Upvotes: 4
Views: 2345
Reputation: 187184
Those are generics. And put simply they let you parameterize a type, allowing you pass other types into it.
So to use your example, you could do something like:
interface SomeType<T, U, V> {
t: T
u: U
v: V
}
const foo: SomeType<string, number, { cool: boolean }> = {
// T U V
t: 'a string',
u: 123,
v: { cool: true }
}
Lots of documentation on generics here: https://www.typescriptlang.org/docs/handbook/generics.html
Upvotes: 6
Reputation: 33
I am not sure on typescript, but at least on some other languages such as C# the T type is a Generic Type Parameter basically it means that you dont need to specify a concrete type of object.
Upvotes: 2