diff --git a/index.d.ts b/index.d.ts index 997870cc..beb34143 100644 --- a/index.d.ts +++ b/index.d.ts @@ -458,4 +458,9 @@ declare const ky: { readonly HTTPError: typeof HTTPError; }; +declare namespace ky { + export type TimeoutError = InstanceType; + export type HTTPError = InstanceType; +} + export default ky; diff --git a/index.test-d.ts b/index.test-d.ts index 1931b815..bafd4900 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -140,3 +140,17 @@ ky(url, { afterStatusCodes: [] } }); + +try { + await ky.get(url); +} catch (error) { + if (error instanceof ky.HTTPError) { + expectType(error); + const {status} = error.response; + expectType(status); + } else if (error instanceof ky.TimeoutError) { + expectType(error); + } else { + throw error; + } +}