0

I want to use typescript in ES6-compatible mode, as a partial replacement for ES6 classes, because it is quite convenient and clear compiler, comparing to traceur/sweet.js macros.

How can I compile files with .js extension?

tsc src/util.js gives error TS5007: Cannot resolve referenced file: 'src/util.js', whereas tsc src/util.ts works just fine.

There are both util.js and util.ts in src directory, but I don’t want to have any .ts files.

dy_
  • 4,795
  • 4
  • 21
  • 28

2 Answers2

1

You can't. It is intentionally not supported by the TypeScript compiler so as to avoid confusion for beginners.

However you can use the typescript compiler api, pass in your content and get the output you can write to file yourself.

basarat
  • 207,493
  • 46
  • 386
  • 462
0

There are plugins for grunt/gulp builders: gulp-typescript and grunt-typescript, which can make any sources, even non-.ts compiled with typescript.

Gulp-typescript implicitly uses typestring, which compiles any string with typescript code, and which is just a wrapper for the typescript.api - node.js API for typescript. Unfortunately, gulp-typescript is not fully complete - no errors logging, no compiling options, so you might need to use typescript.api straightaway.

dy_
  • 4,795
  • 4
  • 21
  • 28