Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#68170 fix: calling @rdfjs/fetch with URL by
Browse files Browse the repository at this point in the history
…@tpluscode

* fix: calling @rdfjs/fetch with URL

* fix: calling @rdfjs/fetch with URL also with factory usage
  • Loading branch information
tpluscode authored Jan 11, 2024
1 parent b281454 commit 245cc9b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion types/rdfjs__fetch-lite/Factory.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface RdfFetchResponse<
}

interface Fetch {
(url: string, options?: FormatsInit): Promise<RdfFetchResponse<DatasetCore>>;
(url: Parameters<typeof fetch>[0], options?: FormatsInit): Promise<RdfFetchResponse<DatasetCore>>;
config(key: string, value: unknown): void;
Headers: Headers;
}
Expand Down
6 changes: 4 additions & 2 deletions types/rdfjs__fetch-lite/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export interface DatasetResponse<
dataset(): Promise<D>;
}

declare function rdfFetch(url: string, options: FormatsInit): Promise<RdfFetchResponse>;
type FetchUrl = Parameters<typeof fetch>[0];

declare function rdfFetch(url: FetchUrl, options: FormatsInit): Promise<RdfFetchResponse>;
declare function rdfFetch<
D extends DatasetCore<OutQuad, InQuad>,
OutQuad extends BaseQuad = Quad,
InQuad extends BaseQuad = OutQuad,
>(
url: string,
url: FetchUrl,
options: FactoryInit<D, OutQuad, InQuad>,
): Promise<DatasetResponse<D, OutQuad, InQuad>>;

Expand Down
14 changes: 13 additions & 1 deletion types/rdfjs__fetch-lite/rdfjs__fetch-lite-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ async function fetchString(): Promise<string> {
return response.text();
}

async function fetchURL(): Promise<string> {
const response = await fetch(new URL("http://example.com"), { formats });
return response.text();
}

async function fetchRequestInfo(): Promise<string> {
const req: Request = <any> {};
const response = await fetch(req, { formats });
return response.text();
}

async function fetchQuadStream(): Promise<Stream> {
const response = await fetch("http://example.com", { formats });
return response.quadStream();
Expand Down Expand Up @@ -44,7 +55,8 @@ async function environmentRawFetch(): Promise<Stream> {
// $ExpectType Headers
const headers = environmentTest.fetch.Headers;

const res = await environmentTest.fetch("foo", { formats });
let res = await environmentTest.fetch("foo", { formats });
res = await environmentTest.fetch(new URL("foo"), { formats });
return res.quadStream();
}

Expand Down

0 comments on commit 245cc9b

Please sign in to comment.