A lightweight, type-safe wrapper around the native fetch API that uses TypeScript generics to enforce request and response types. Version 1.1.4 is the latest stable release. It provides opinionated defaults (JSON encoding/decoding, status code validation, timeouts) while allowing full customization. Compared to alternatives like axios or ky, ts-fetch focuses on simplicity and type safety without additional dependencies, returning a discriminated union for success/error/network-error states. The package ships with TypeScript definitions and has a small footprint, suitable for projects wanting typed HTTP requests without heavy abstraction.
npm install ts-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows a GET request with typed success and error responses, including custom headers and handling all possible response statuses.
Set `jsonResponse: false` in the request params if the response is not JSON.
Adjust `timeout` in the request params to a higher value if needed.
Use `validStatusCodes` or adjust `validStatusCodeStart`/`validStatusCodeEnd` to include desired codes.
Run `npm install ts-fetch` and use `import { request } from 'ts-fetch'`Use `import { request } from 'ts-fetch'` instead of `import request from 'ts-fetch'`Check `if (response.status === 'OK')` before accessing response.data
No dependency data recorded yet.