我正在尝试学习https://github.com/TypeStrong/ts-node。我写了两个文件作为一个简单的例子。它们都在同一个目录中,目前与 package.json 不在同一个文件夹中
/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');
测试.ts
export class Test {
log(message: string) {
console.log(`Test ${message}`);
}
}
我正在运行以下脚本:
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
我希望在控制台上看到“测试消息”。