【发布时间】:2017-12-20 17:06:47
【问题描述】:
我的命令行应用程序的主文件中有以下代码:
const init = async (): Promise<types.IContextObject> => {
let context: types.IContextObject;
try {
context = await createContext(dataObj);
} catch (e) {
dataObj.errors.insert({ message: e.message });
process.exit(1);
}
context.info.insert({
message: `Using Rules: `.bold + `${Object.keys(context.rules).join(', ')}`
});
return context;
};
在此我得到以下编译器错误:
Variable 'context' is used before being assigned.
let context: types.IContextObject
如果我在 try 块中移动最后两行,我会得到:
Function lacks ending return statement and return type does not include 'undefined'.
【问题讨论】:
标签: typescript asynchronous async-await