yangblink

问题一个 typescript 类型包裹问题

  •  
  •   yangblink · Jan 25, 2024 · 2057 views
    This topic created in 844 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   ·   1248 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 17:34 · PVG 01:34 · LAX 10:34 · JFK 13:34
    ♥ Do have faith in what you're doing.