2014-06-23 41 views
1

以下內容會導致一個相當神祕的TypeScript構建錯誤:Exported variable 'res' has or is using private type 'Result'導出的變量已經或正在使用私人類型TypeScript錯誤

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() {}; 

這一切ok如果任:

  • 刪除的try/catch
  • 不導出功能what

這是怎麼回事?

回答

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); 
    } 
}; 
+1

整潔。謝謝!有沒有公​​開的問題,還是應該提交? – ubershmekel

相關問題