2017-03-14 10 views
1

https://github.com/TypeStrong/ts-nodeを学習しようとしています。私は単純な例として2つのファイルを書きました。彼らは、package.json単純なTypeScriptノードをコンパイルできません。

/package.json 
/src/build-lib/run-ts.js 
/src/build-lib/Test.ts 

実行ts.js

require('ts-node').register(); 
const Test = require('./Test.ts').Test; // Tried with and without .ts extension 
const tester = new Test(); 
tester.log('Message'); 

Test.ts

export class Test { 
    log(message: string) { 
     console.log(`Test ${message}`); 
    } 
} 

Iと同じフォルダに、現在ではありません同じディレクトリにともに次のスクリプトを実行しています:

ts-node src/build-scripts/gen-xml.js 

そして次のコンパイルエラーが発生します

/Users/jmendes/gitclient/vcd-ui/content/core/node_modules/ts-node/src/index.ts:319 
     throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset)) 
      ^
TSError: ⨯ Unable to compile TypeScript 
src/build-scripts/Test.ts (7,36): Parameter 'message' implicitly has an 'any' type. (7006) 
    at getOutput (/Users/jmendes/gitclient/vcd-ui/content/core/node_modules/ts-node/src/index.ts:319:17) 
    at /Users/jmendes/gitclient/vcd-ui/content/core/node_modules/ts-node/src/index.ts:350:18 

「テストメッセージ」がコンソールに表示されることが予想されます。

答えて

2

JavaScriptファイル(run-ts.js)は、それ自体がrequireの呼び出しを傍受するTypeScriptを登録しているようです。

ts-nodeの代わりにnodeというファイルを実行しようとしましたか?

+0

それは作業を行います。私は問題が何だったのかよく分かりません。 'ts-node'を呼び出すと、すべてのファイルがTypeScriptでなければなりませんか?ちなみに、私がts-nodeを使ってスクリプトを実行した理由は、最初run-tsがTypeScriptファイルだったからですが、TS定義を提供しないHandleBarsをインポートしなければならないので、run-ts.jsに変更しました –

0

私のための修正は、その後、package.jsonからts-nodetypescriptを削除することでした。私は、ノードを実行したときに

npm install ts-node --save-dev 
npm install -g typescript --save-dev 
関連する問題