type NoParamOptions = { success: (res: string) => void; fail: (res: string) => void; complete: (res: string) => void; }; type StringParamOptions = { input:string; success: (res: string) => void; fail: (res: string) => void; complete: (res: string) => void; }; type inputJSON = { inputText:string, errCode:number } type JsonParamOptions = { input:inputJSON; success: (res: string) => void; fail: (res: string) => void; complete: (res: string) => void; }; /** * 导出一个带callback的同步方法 * @param opts */ export function callWithoutParam(opts: NoParamOptions) { setTimeout(function() { opts.success(); }, 500); return { name: "doSthWithCallback" }; } export function callWithStringParam(input:string,success: (res: string) => void) { setTimeout(function() { success(input); }, 500); return { name: "doSthWithCallback" }; } export function callWithJSONParam(opts: JsonParamOptions) { opts.input.errCode = 10; setTimeout(function() { opts.success(opts.input); }, 500); return { name: "doSthWithCallback" }; }