Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Created July 12, 2016 10:54
Show Gist options
  • Select an option

  • Save Ciantic/1dcb38fa0c8dcde68c6705641197ae48 to your computer and use it in GitHub Desktop.

Select an option

Save Ciantic/1dcb38fa0c8dcde68c6705641197ae48 to your computer and use it in GitHub Desktop.
typesafe api - thinking
abstract class ApiPromise<T> extends Promise<T> {
abstract onError(errorCode: string, cb: (data?: Object) => void);
abstract onError(errorCode: "VALIDATION_ERROR", cb: (data?: {
fields?: {
[fieldName: string] : string[]
},
messages?: string[]
}) => void);
}
export const Api = {
Account: {
Register : async (vars: { email: string, code: string }) => {
// TODO
},
ResetPassword : async (vars: { email: string, code: string, newPassword: string }) => {
// TODO
}
}
}
// Api.
declare namespace Test {
export interface Api {
callAsync(name: "Account.Register", body: { email: string, code: string}): ApiPromise<{}>
}
}
declare namespace Test {
export interface Api {
callAsync(name: "Account.ResetPassword", body: { email: string, code: string, newPassword: string }): ApiPromise<{}>
}
}
let Api2: Test.Api;
// Api2.callAsync()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment