import { expectType } from 'tsd'; import ImgixAPI, { RequestResponse, APIError, JsonArray, JsonMap } from '.'; const API_KEY = 'ak_abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789'; const SOURCE_ID = '012abc345def678abc901def'; const BAD_REQUEST = '404_endpoint'; const ASSETS_ENDPOINT = `assets/${SOURCE_ID}`; const BODY_BUFFER = Buffer.alloc(1); const BODY_JSON = { data: 'test' }; const ix = new ImgixAPI({ apiKey: API_KEY, version: 1, pluginOrigin: 'management', }); expectType(ix); expectType(ImgixAPI.APIError); expectType>(ix.request('sources')); expectType>(ix.request(`${ASSETS_ENDPOINT}`)); expectType>( ix.request(`sources/upload/${SOURCE_ID}/image.jpg`, { method: 'POST', body: BODY_BUFFER, }), ); expectType>( ix.request('sources', { method: 'POST', body: BODY_JSON, }), ); ix.request('sources').then((response) => { expectType(response.data); expectType(response.included); expectType(response.jsonapi); expectType(response.meta); }); expectType>( ix.request(`${BAD_REQUEST}`).catch((error: APIError) => { expectType(error.response); expectType(error.message); expectType(error.status); expectType<() => string>(error.toString); }), ); async function processRequest(request: Promise) { const response = await request; expectType(response); } processRequest(ix.request('sources')); try { () => {}; } catch (error) { if (error instanceof APIError) { expectType(error.response); expectType(error.message); expectType(error.status); expectType(error.toString()); } }