Skip to content

Instantly share code, notes, and snippets.

@tompng
Created June 13, 2020 17:41
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 tompng/72d69baee8f0a7812cfdd5333f89b250 to your computer and use it in GitHub Desktop.
Save tompng/72d69baee8f0a7812cfdd5333f89b250 to your computer and use it in GitHub Desktop.
type MethodPathParams = {
get: {
'foo/:fooId': {
fooId: number
foo?: number
}
'bar/:baz': {
baz: number
bar?: number
}
}
delete: {
'foo/:fooId': { id: number }
}
}
function request<M extends keyof MethodPathParams, P extends keyof MethodPathParams[M]>(
method: M,
path: P,
params: MethodPathParams[M][P]
) {
console.log(method, path, params)
}
request('get', 'foo/:fooId', { fooId: 3 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment