https://github.com/TypeStrong/ts-node을 배우려고합니다. 나는 두 개의 파일을 단순한 예제로 썼다. 그들은 package.json간단한 TypeScript node-ts 예제를 컴파일 할 수 없습니다.
/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
"테스트 메시지"가 콘솔에 표시 될 것으로 예상됩니다.
그것은 작업을 수행합니다. 나는 그 문제가 무엇인지 이해하지 못한다. 'ts-node'를 호출하면 모든 파일이 TypeScript 여야합니까? 그런데 ts-node를 사용하여 스크립트를 실행 한 이유는 처음에는 run-ts가 TypeScript 파일 이었기 때문입니다.하지만 TS 정의를 제공하지 않는 HandleBars를 가져와야하므로 run-ts.js로 변경했습니다 –