arktypea
arktype15mo ago
Cobain

Function which receives a arktype's 'type'

I'm trying to do something like this:
  async rateLimitedCallApi<T>(url: string, schema: Type<T>): Promise<T> {
    await this.rate_limiter.acquire();
    
    const response = await fetch(url, this.request_data);
    if (!response.ok) {
      throw Error(`Invalid request: ${response}`)
    }
    
    const parsedResponse = schema(await response.json());

But the parsedResponse isn't of type T, so how do I make this function accept as schema anything created using type({...})
Was this page helpful?