-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Types? #43
Comments
Happy to merge a PR! |
I tried to write some types, but I was defeated by TypeScript features I don't fully grasp (namely overloading the method in a way that would set the right output type depending on |
This is what I've been using: declare module "@11ty/eleventy-fetch" {
type FetchType =
| "json"
| "buffer"
| "text";
type EleventyFetchOptionsBase<TType extends FetchType> = {
type: TType;
directory?: string;
concurrency?: number;
fetchOptions?: RequestInit;
dryRun?: boolean;
removeUrlQueryParams?: boolean;
verbose?: boolean;
hashLength?: number;
duration?: string;
formatUrlForDisplay?: (url: string) => string;
}
type EleventyFetch = <TReturn, TType extends FetchType = "json">(url: string, options: EleventyFetchOptionsBase<TType>) =>
Promise<
TType extends "json" ? TReturn :
TType extends "buffer" ? Buffer :
TType extends "text" ? string :
never
>;
const fetch: EleventyFetch;
export default fetch;
} I think it handles most scenarios. @gBasil do you want to see if that handles at least your use-case? |
I ended up switching off of |
No worries @gBasil! I'll make a pr either way. |
Would it be feasible to have TypeScript types (
.d.ts
) available for this package? There doesn't seem to be anything on DefinitelyTyped.The text was updated successfully, but these errors were encountered: