declare var smartformsrecordingparams:any; export class AsyncAjax{ public static Post(data:any):Promise{ return new Promise(async (resolve)=>{ jQuery.post(smartformsrecordingparams.ajaxurl,data,resolve,'json'); }); } public static PostWithToken(data:any):PromiseWithToken{ let token=new PromiseToken(); return { Promise:new Promise>(async (resolve)=>{ jQuery.post(smartformsrecordingparams.ajaxurl,data,(data)=>{ resolve({WasCancelled:token.WasCancelled,Result:data}) },'json'); }), Token:token } } } export class PromiseToken{ public WasCancelled:boolean=false; public Cancel(){ this.WasCancelled=true; } } interface PromiseWithToken{ Promise:Promise>; Token:PromiseToken; } interface ResultWithToken{ WasCancelled:boolean; Result:T; }