Generic type variables

Wrap<Opening, ...>

Openingextendsstring=string

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

wrap.class.ts
class Wrap<
  Opening extends string = string, // <--- Declare generic type variable Opening.
  Text extends string = ``,
  Closing extends string = string
> extends String {
  ...
  constructor(
    opening: Opening, // <--- Capture generic type variable Opening.
    closing: Closing,
    text: Text = '' as Text
  ) { ... }
  ...
}

Wrap<...,Text, ...>

Textextendsstring=``

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

The constructor text parameter is optional, and if not provided, the default value of the generic type variable Text is not captured, but it's an empty string from the declaration.

Wrap<...,Closing>

Closingextendsstring=string

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

Last updated

Was this helpful?