Created
December 8, 2018 16:06
-
-
Save ratbeard/e88386280bb3b06fa5f092fa5fb9382a 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
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