泛型类型

class Size<T> {

    constructor(
        public width: T
        public height: T) {}

    asText() {
        return `[${this.width}${this.height}]`
    }
}

let sizeInt = new Size(58)
let textInt = sizeInt.asText()
//textInt is "[5; 8]"

let sizeFloat = new Size(3.71.58)
let textFloat = sizeFloat.asText()
//textFloat is "[3.7; 1.58]"

let sizeStr = new Size<string>("12dp""7dp")
let textStr = sizeStr.asText()
//textStr is "[3.7; 1.58]"

console.log(`textInt is "${textInt}"`)
console.log(`textFloat is "${textFloat}"`)
console.log(`textStr is "${textStr}"`)