Skip to content

Instantly share code, notes, and snippets.

@ratbeard
Created December 8, 2018 16:06
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 ratbeard/e88386280bb3b06fa5f092fa5fb9382a to your computer and use it in GitHub Desktop.
Save ratbeard/e88386280bb3b06fa5f092fa5fb9382a to your computer and use it in GitHub Desktop.
interface RequestOptions {
authToken?: string
}
interface Fun {
age: number;
}
const InitEndpoint = {
get({ id }: { id: string }, options?: RequestOptions): Promise<Fun> {
return Promise.resolve({ age: 1})
},
list(args: void, options: RequestOptions): Promise<Fun[]> {
return Promise.resolve([{ age: 1}])
}
}
async function request<T, P, O>(
fn: (params: P, options: O) => Promise<T>,
args?: P,
options?: O
): Promise<T> {
console.log('gettin it!')
return fn(args, options)
}
async function main() {
request(InitEndpoint.get, { id: '1' }, {}).then(x => console.log(x.age))
const funs = await request(InitEndpoint.list)
console.log(funs[1].age)
await this.playbookServer.request(InitEndpoint.list)
await request(InitEndpoint.list, { a: 5 })
await request(InitEndpoint.list, { a: 5 }, { authToken: '6' })
InitEndpoint.get({ id: '1' }, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment