Ts中如何获取class构造函数的参数类型

322 阅读1分钟

最近在学习ts,算是一个笔记吧。

class chinesePeople {
    constructor(public name:string, public sex:string,public phone:string) {
        
    }
}


type test<T> = T extends new (...args:infer P)=> any ? P : never;


const ttt:test<typeof chinesePeople> = ['ss','asd','123'];

到最后ttt的类型为一个元组

image.png