Typescript: Adding possibility to change file extension of generated files

Created on 11 Jul 2015  路  9Comments  路  Source: microsoft/TypeScript

It's my understanding (after some stackoverflow checking) that at the moment it's impossible to specify a file extension for js file generated by the compiler.
Could this be possible in the future ?

Discussion

Most helpful comment

One use case for this would be to allow for a mixed JS/TS code base sharing the same directory structure, and still being able to distinguish between a generated and a source file using the file extension. For example, I could output compiled JS files with a .ts.js extension, and add *.ts.js to my .gitignore file, and have one src directory where I can gradually migrate files from javascript to Typescript.

All 9 comments

We could easily remove the restriction, but would need to understand why that would be a good thing. It would be easy to accidently specify a .ts file as an output (via shell tab completion) and overwrite a source file, which isn't a great user experience.

Can you talk about your use case a bit?

I'm using Meteor and the community (in a few months in core) is adding the possibility to import ES6 modules.
Meteor works by bundling all js files to a monolithic file which is sent to the client.
The exception to this are files that should not be bundled. Hence es6 modules should be named filename.import.js or filename.import.jsx to be excluded from the bundle.
This was a possibility i was seing to make typescript work with Meteor since there are not close friends actually (lot of problems making ts modules quite impossible to work with with Meteor, among other problems).

Of course filename.import.ts will compile to filename.import.js. Will that not work in your use case?

I didn't think of that !
Is there such a possibility for jsx ?

'.tsx' will compile to '.jsx' if using --jsx preserve or '.js' if using --jsx react. Otherwise the behavior is the same.

Thank you.

One use case for this would be to allow for a mixed JS/TS code base sharing the same directory structure, and still being able to distinguish between a generated and a source file using the file extension. For example, I could output compiled JS files with a .ts.js extension, and add *.ts.js to my .gitignore file, and have one src directory where I can gradually migrate files from javascript to Typescript.

Pingback from #18442: allowing arbitrary output extension would support consumers that expect .mjs or .es6 (or whatever).

@RyanCavanaugh

We could easily remove the restriction, but would need to understand why that would be a good thing. It would be easy to accidently specify a .ts file as an output (via shell tab completion) and overwrite a source file, which isn't a great user experience.

Can you talk about your use case a bit?

With this configuration option we can use the same workflow https://bucklescript.github.io/docs/en/interop-with-js-build-systems.html#tips-tricks and add .ts.js to VCS ignore file. Now we have to use .ts.ts extension and it looks bad.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xealot picture xealot  路  150Comments

tenry92 picture tenry92  路  146Comments

fdecampredon picture fdecampredon  路  358Comments

Gaelan picture Gaelan  路  231Comments

yortus picture yortus  路  157Comments