yangblink

问题一个 typescript 类型包裹问题

  •  
  •   yangblink · Jan 25, 2024 · 2192 views
    This topic created in 904 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   ·   2499 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 00:40 · PVG 08:40 · LAX 17:40 · JFK 20:40
    ♥ Do have faith in what you're doing.