yangblink

问题一个 typescript 类型包裹问题

  •  
  •   yangblink · Jan 25, 2024 · 2104 views
    This topic created in 865 days ago, the information mentioned may be changed or developed.
    1 replies    2024-01-25 21:58:35 +08:00
    Opportunity
        1
    Opportunity  
       Jan 25, 2024
    这种?
    ```
    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'))
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1258 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 23:38 · PVG 07:38 · LAX 16:38 · JFK 19:38
    ♥ Do have faith in what you're doing.