Reputation: 92324
I am trying to learn https://github.com/TypeStrong/ts-node. I've written two files as a simplistic example. They are both in the same directory, which is currently not in the same folder as package.json
/package.json
/src/build-lib/run-ts.js
/src/build-lib/Test.ts
run-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'm running the following script:
ts-node src/build-scripts/gen-xml.js
And I'm getting the following compilation error
/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
I expected to see "Test Message" on the console.
Upvotes: 3
Views: 16260
Reputation: 416
The fix for me was to remove ts-node
and typescript
from package.json
, then:
npm install ts-node --save-dev
npm install -g typescript --save-dev
Upvotes: 1
Reputation: 546473
It looks like you have a JavaScript file (run-ts.js) which is itself registering TypeScript to intercept any require
calls made.
Have you tried running that file with just node
instead of ts-node
?
Upvotes: 4