Last active
July 17, 2022 07:11
-
-
Save gnowland/004255256261fac98deabe9ac6a9c4e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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