V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yangblink
V2EX  ›  TypeScript

问题一个 typescript 类型包裹问题

  •  
  •   yangblink · 93 天前 · 717 次点击
    这是一个创建于 93 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1 条回复    2024-01-25 21:58:35 +08:00
    Opportunity
        1
    Opportunity  
       93 天前
    这种?
    ```
    export type Client = typeof client;
    export type ApiCall<T> = (client: Client) => Promise<T>;
    export function useApi() {
    return async function <T extends {
    data: any;
    error?: any;
    response: Response;
    }>(apiCall: ApiCall<T>): Promise<Awaited<ReturnType<ApiCall<T>>>['data']> {
    const response = await apiCall(client);
    return response.data;
    };
    }

    client.GET('/url2')
    const api = useApi();

    const r = await api(client => client.GET('/url2'))
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2998 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 14:09 · PVG 22:09 · LAX 07:09 · JFK 10:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.