Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnowland/004255256261fac98deabe9ac6a9c4e6 to your computer and use it in GitHub Desktop.
Save gnowland/004255256261fac98deabe9ac6a9c4e6 to your computer and use it in GitHub Desktop.
type FetchSecure = (
...args: [...[keycloak: KeycloakInstance], ...Parameters<typeof fetch>]
) => ReturnType<typeof fetch>;
For example, this takes the parameters from the http fetch api and assigns them to my new type with my response type override:
```
type Fetch = (...args: [...Parameters<typeof fetch>]) => Promise<any>;
// result: (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<any>
```
And then I can add my own parameters, like so:
```
type FetchHandler = (...args: [...Parameters<Fetch>, ...[anon?: boolean]]) => ReturnType<Fetch>
// results: (input: RequestInfo | URL, init?: RequestInit | undefined, anon?: boolean | undefined) => ReturnType<Fetch>
```
If we want get the individual function parameters we can do:
```
type InputParam = Parameters<Fetch>[0];
type InitParam = Parameters<Fetch>[1];
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment