# ts-generic-fetch

> Fetch extended with generic type

Latest version **1.0.0-beta** (published 2021-07-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-generic-fetch
pnpm add ts-generic-fetch
yarn add ts-generic-fetch
bun add ts-generic-fetch
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta |
| Published | 2021-07-12 |
| First published | 2021-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Michał Kardyś |
| Maintainers | kardysm |
| Keywords | typescript, fetch, generic, api |

## Links

- npm: https://www.npmjs.com/package/ts-generic-fetch
- Repository: https://github.com/kardysm/ts-generic-fetch
- Homepage: https://github.com/kardysm/ts-generic-fetch#readme
- Issues: https://github.com/kardysm/ts-generic-fetch/issues
- npm.io page: https://npm.io/package/ts-generic-fetch

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.0-beta (latest) — 2021-07-12
- 0.0.2 — 2021-07-12
- 0.0.1 — 2021-07-12

## README

# ts-generic-fetch

Fetch extended with generic type

## Install

```
yarn add --dev ts-generic-fetch
// or
npm install --save-dev ts-generic-fetch
```

## Use

In an entrypoint of your app:
```
import 'ts-generic-fetch'
```

Wherever you need built-in `fetch` in your files:

```
  const jsonResult = fetch<{returnTypeProp: 'someValue'}>('https://use-fetch-as-usual')
  const textResult = fetch<'expectedString'>('https://use-fetch-as-usual')
```

* * *
## The code 

Whole package is just short snippet which enhances built-in typings. 

You could either: 
- use the snippet if you don't want external deps or 
- install npm package [ts-generic-fetch](https://www.npmjs.com/package/ts-generic-fetch)

```
export {}

declare global {
  interface TypedResponse<ReturnData> extends Response {
    json() : ReturnData extends {} ? Promise<ReturnData> : ReturnType<Response["json"]>
    text() : ReturnData extends string ? Promise<ReturnData> : ReturnType<Response["text"]>
  }
  function fetch<T>(input: RequestInfo, init?: RequestInit): Promise<TypedResponse<T>>;
}
```

---
_Source: https://npm.io/package/ts-generic-fetch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
