TypeScript-泛型

50 阅读1分钟

1.简单定义

function aaa<T>(arg:T):T{
    return T
}

2.接口泛型

interface Person<T>{
    name:T
    (arg:T):T
}

3.泛型约束

interface lll{
    length:number
}
function lll<T extends lll>(arg:T):T{
    console.log(arg.length)
    return arg
}