typeidGeneric

View sourcetypeidGeneric<T, U extends ConstructorFn[]>(type: Constructor<T>, types: [...U[]]): TypeId

Derives a generic TypeId lookup key from a constructor and its constructor arguments.

For a non-empty types array, the ID is the base constructor name followed by the argument constructor names in angle brackets, with no spaces. Use the result with APIs that register or look up metadata for the generic type. For an empty array, this function returns the same ID as typeid for type. It uses each constructor’s .name; it does not inspect or instantiate any constructor.

Examples

const valuesId = typeidGeneric(Map, [String, Number])
// valuesId === 'Map<String,Number>'

Type Parameters

T

U extends ConstructorFn[]

Parameters

NameDescriptionDefault
type

The base generic constructor.

—
types

The constructors used as the generic arguments.

—

Returns

An ID such as Map<String,Number> or, with no arguments, Map.