泛型类

类,很像接口,可以是泛型的。 当使用 new 实例化泛型类时,其类型参数的推断方式与函数调用中的方式相同:

Classes, much like interfaces, can be generic. When a generic class is instantiated with new, its type parameters are inferred the same way as in a function call:

class Box<Type> {
  contents: Type;
  constructor(value: Type) {
    this.contents = value;
  }
}

const b = new Box("hello!");
//    ^?

oAnEvwB5ZbSBiugUG70IQsu46pteN18QEUa8esYiP92IKUdhKkUcg5m5XLLGvCenU4JZIQBBN5HuPDnd313T7eiORKYOe/D8KHtvCMuXGjiWJVL7I9x5xJ9kmH4qRx+d4SYk95Y+X3ush3U2pdd+OstZ6pJ9HeZ+X3JChdZHyvjeJrGImwhO+4rn9ACf91g8dkx/j/1/GDr4bwR9EcAngw==