Generic type variables

Attribute<Name, ...>

​A generic type variable constrained by the string, by default of the value captured from the provided name indicates the opening type of a new Attribute instance.

class Attribute<
  Name extends string = string, // <--- Declare generic type variable Name.
  Value extends string = string
> extends String {
  ...
  constructor(
    name: Name,   // <--- Capture generic type variable Name.
    value: Value  
  ) { ... }
  ...
}

Attribute<...,Value>

​A generic type variable constrained by the string, by default of the value captured from the provided value indicates the value type of a new Attribute instance.

class Attribute<
  Name extends string = string,
  Value extends string = string // <--- Declare generic type variable Value.
> extends String {
  ...
  constructor(
    name: Name,
    value: Value  // <--- Capture generic type variable Value.
  ) { ... }
  ...
}

Last updated