以下内容会产生一个相当神秘的TypeScript构建错误:Exported variable 'res' has or is using private type 'Result'
。
interface Result {
status: string;
comment: string;
}
function runTest(st: any) {
try {
} catch (err) {
console.log('Failed test task: ' + err);
console.log('Failed test task: ' + st.name);
console.log(err.stack);
var res: Result = {
status: 'bad',
comment: 'Nodejs exception: ' + err,
};
//saveTestResult(st, res);
}
};
export function what() {};
如果其中任何一个都可以:
what
这里发生了什么?
答案 0 :(得分:2)
您在编译器中发现了一个错误。你可以通过移动res
的声明来解决它(这不会改变代码的行为):
function runTest(st: any) {
var res: Result;
try {
} catch (err) {
console.log('Failed test task: ' + err);
console.log('Failed test task: ' + st.name);
console.log(err.stack);
res = {
status: 'bad',
comment: 'Nodejs exception: ' + err,
};
//saveTestResult(st, res);
}
};