3

ts 递归的将一个对象上的所有方法改成返回promise

 2 years ago
source link: https://shenzilong.cn/other/ts%20%E9%80%92%E5%BD%92%E7%9A%84%E5%B0%86%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E4%B8%8A%E7%9A%84%E6%89%80%E6%9C%89%E6%96%B9%E6%B3%95%E6%94%B9%E6%88%90%E8%BF%94%E5%9B%9Epromise.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ts 递归的将一个对象上的所有方法改成返回promise

type Promiseify<T> = T extends Promise<infer P> ? T : Promise<T>;
type apisPromise<P> = {
  readonly [K in keyof P]: P[K] extends (...args: any) => any
    ? (...arg: Parameters<P[K]>) => Promiseify<ReturnType<P[K]>>
    : P[K] extends Object
    ? apisPromise<P[K]>
    : P[K];
};


by 崮生 from 崮生 • 一些随笔 🎨,欢迎 赞助本文
本文欢迎分享与聚合,全文转载未经授权( 联系我)不许可。

神仙散棒槌IT源点monaco-editor崮生 • 一些随笔 🎨 赞助我 copyright © 2018.11.6 - 2021.10 湘ICP备18021783号 GIT HUB


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK