Created
July 12, 2016 10:54
-
-
Save Ciantic/1dcb38fa0c8dcde68c6705641197ae48 to your computer and use it in GitHub Desktop.
typesafe api - thinking
This file contains hidden or 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
| 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