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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Of course I use --out option, I just specified the issue there.
Explained how gulp/grunt do it. tsc is not supported
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.