Skip to content
Myr

fetch-extensions.ts

This file

Path

test-d/fetch-extensions.ts

21 lines · 821 bytes · TypeScript

Last changed by

Fix CISindre Sorhusbefore adoptiond9ddb03

History of this file

Take it

Explain both causes of a missing response and document the new validationSindre Sorhusbefore adoption58233f1

line 1why, one step back
1import {expectTypeOf} from 'expect-type';

Fix docsSindre Sorhusbefore adoptiond4ce7b1

lines 2–3why, one step back
2import type {Options} from 'ky';
3

Explain both causes of a missing response and document the new validationSindre Sorhusbefore adoption58233f1

lines 4–16why, one step back
4type NextFetchRequestConfig = {
5 revalidate?: number | false;6 tags?: string[];7};89// Frameworks and runtimes declare their fetch-only extensions on the global `RequestInit`, the way Next.js declares `next` and `@types/node` declares `dispatcher`. Ky must pick up that type rather than redeclare the option, which conflicts with the ambient declaration.10declare global {11 // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Global augmentation requires an interface.12 interface RequestInit {13 next?: NextFetchRequestConfig;14 }15}16

Fix docsSindre Sorhusbefore adoptiond4ce7b1

lines 17–18why, one step back
17const withNext: Options = {next: {revalidate: 0}};
18

Explain both causes of a missing response and document the new validationSindre Sorhusbefore adoption58233f1

lines 19–20why, one step back
19expectTypeOf<Options['next']>().toEqualTypeOf<NextFetchRequestConfig | undefined>();
20

Fix CISindre Sorhusbefore adoptiond9ddb03

line 21why, one step back
21expectTypeOf(withNext).toEqualTypeOf<Options>();