2016-09-26 17 views
0

我正在學習打字稿。我的tsconfig.json中的哪個選項導致錯誤?

interface FooOptions { 
    x: string; 
    y: string; 
} 

function getFoo(opt: FooOptions) { 
    return opt.x + opt.y; 
} 

export {getFoo, FooOptions}; 

運行node_modules/.bin/tsc提供了以下錯誤:

$ node_modules/.bin/tsc 
t.ts(6,22): error TS4078: Parameter 'opt' of exported function has or is using private name 'FooOptions'. 

node_modules/.bin/tsc t.ts成功運行。

根據the document

By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.

哪個選項在我tsconfig.json導致錯誤?那錯誤是什麼意思?

{ 
    "compilerOptions": { 
    "target": "es5", 
    "outDir": "dist", 
    "module": "commonjs", 
    "declaration": true, 
    "noImplicitAny": true, 
    "removeComments": true, 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "inlineSources": true 
    }, 
    "exclude": [ 
    "node_modules", 
    "dist" 
    ] 
} 

回答

0

您需要導出接口,以及:

export interface FooOptions { 
    x: string; 
    y: string; 
} 
+0

這工作!我想知道'export interface FooOptions'和'export {getFoo,FooOptions}之間有什麼區別;'爲什麼'node_modules/.bin/tsc t.ts'成功運行? – zjk

+0

我不知道爲什麼當你運行'tsc'時你沒有得到這個錯誤。當我試圖重現這個問題時,錯誤正在被拋出 –