作者:xie392地址:https://v.douyin.com/ieQtm3cC/更新时间:2024-12-21
1type sum = (a:number, b: number) => number2type concat = (a:any[], b:any[] ) => any[]34// 类似于 ReturnType<T>5// infer 推断6type Return<T> = T extends (...args:any[]) => infer K ? K : T78let sumResult: ReturnType<sum> // number9let concatResult: Return<concat> // any[]101112// 例子13type PromiseType<T> = T extends Promise<infer K> ? PromiseType<K> : T14type pt = PromiseType<Promise<Promise<string>>> // string