Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the .js and .es file extensions for TypeScript files #2302

Closed
marinasundstrom opened this issue Mar 11, 2015 · 30 comments
Closed

Enable the .js and .es file extensions for TypeScript files #2302

marinasundstrom opened this issue Mar 11, 2015 · 30 comments
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@marinasundstrom
Copy link

Enable the .js, .jsx, .es and .es6 file extensions for TS compiler file inputs and module imports. This is already supported by other transpilers, such as babel.

The feature would ideally be added as an option in the compiler. With .js together with .ts on by default, but .ts still being prefered.

This would cause the files with the enabled extensions to, just as .ts-files today, be processed (e.g. in and IDE), and transformed if the options so allow it.

One objection to this would be that this could potentially confuse scripts that are using TypeScript-specific features with scripts using official ES6 features. I don't personaly see this as an issue. It is up to the developers to come up with conventions in their own projects.

@mhegazy mhegazy added the Suggestion An idea for TypeScript label Mar 11, 2015
@dpen2000
Copy link

This would probably mean GitHub wouldn't be able to detect whether a repository is using javascript or typescript

@NoelAbrahams
Copy link

This would cause the files with the enabled extensions to, just as .ts-files today, be processed (e.g. in and IDE), and transformed if the options so allow it.

What sort of processing are you suggestion for .js files?

@marinasundstrom
Copy link
Author

@NoelAbrahams Treating them as TypeScript-files and selectively enabling certain features.

@CyrusNajmabadi
Copy link
Contributor

@RobertSundstrom If you would like them to be treated as TypeScript files, why not rename them to .ts?

@NoelAbrahams
Copy link

I actually ran into a use-case today for wanting to compile a .js file.

We have moment.js in a Visual Studio TypeScript project. This is the only JavaScript file in the project. The project has the options "combine output into a single file" and "no implcity any" set.

We want to include moment.js in the combined output file.

I tried setting Build Action: TypeScriptCompile on the properties page for moment.js, but got the error:

moment.js' must have extension '.ts' or '.d.ts'

For the use-case above we cannot simply change the extension to .ts because moment.js is not annotated and will not compile under the noimplicitany flag.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 15, 2015

@NoelAbrahams this is slightly different from the original proposal from @RobertSundstrom , you want the compiler to read in .js files, write them to the output, but do not report any errors in them. is this accurate?

@NoelAbrahams
Copy link

@mhegazy, I would see it as an enhancement to the original request. The following would happen:

  • moment.js would be parsed by the compiler and the compiler would report any syntax errors.
  • noimplicitany would be ignored, since .js files won't have any type annotation in any case.
  • The .js would be included in the output, hence all output options should be honoured, e.g. redirect-output-to-directory, combine-output-into-single-file.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 15, 2015

What about other semantic errors, e.g.:

var x = 2;
if (false) {
     x = "string":
}

or

var x = 1;

var x = "";

should these be reported for moment.js?

@NoelAbrahams
Copy link

I think for most users the processing of .js files is going to be for dealing with very unusual requirements.

We need to include moment.js in a project because non of the major CDN providers that we use (Google/Microsoft) currently host this library.

If people want the compiler to catch semantic errors then they should be writing TypeScript. I think for .js files only syntax errors should be reported.

@Raynos
Copy link

Raynos commented May 3, 2015

👍

I would also like to typecheck javascript files.

My use case is to use the typescript type checker but still author ES5 code that does not need to be compiled for someone to use it.

@ianfp
Copy link

ianfp commented Jun 12, 2015

+1 Being able to compile files with a .js extension using tsc would be very useful for people like me, who are exploring the possibility of migrating an existing Javascript project to TypeScript. I don't want to have to rename all of my .js files, and I certainly don't want to hack Typescript like this guy suggests.

@kitsonk
Copy link
Contributor

kitsonk commented Jun 13, 2015

@ianfp it sounds like a totally different problem/subject in that you are looking for a JavaScript -> TypeScript migrator that helps you easily get on the right path of converting a code base from JavaScript to TypeScript. Sounds like an interesting project...

@ianfp
Copy link

ianfp commented Jun 15, 2015

@kitsonk Perhaps I misunderstood what this issue is about... but yes, I'd basically like to replace r.js with tsc as my compiler and then start migrating the code from there. Perhaps this is not possible?

@forbesmyester
Copy link

I'd like to run TS as an extra to ESLint (sometimes) but also be able to benefit from some of the advanced type stuff you guys have available autocompletion in VIM.

@adidahiya
Copy link
Contributor

@forbesmyester what do you mean by "as an extra to ESLint (sometimes)"? FYI https://github.com/palantir/tslint exists

@forbesmyester
Copy link

@adidahiya did not know about tslint, does it give the same results of mistakes that TypeScript itself seems to? In which case that part of the desire is no longer relevant, would still like to use it for the VIM omni completion / hints as they are really good. Requiring a .ts extension is annoying as it means that you need buy in from a whole team as apposed to just a single developer using it for some of the smaller (editor / linting) enhancements.

@ldminoc
Copy link

ldminoc commented Sep 25, 2015

Sorry for being late to the conversation but I'm currently working on a project where it would be nice to have the original requested feature. Our project code base contains a mix of open source derivative code written in js (es5), es6 and TypeScript. It would be nice if TypeScript could be used to transpile es6 as well, rather than resorting to another transpiler such as babel to process the es6 source.

@RyanCavanaugh RyanCavanaugh added the In Discussion Not yet reached consensus label Sep 28, 2015
@ghost
Copy link

ghost commented Oct 1, 2015

I am in the same situation and in fact waiting for this feature to move to VSC!

@anievagomez
Copy link

I have the same needs as ldminoc and robertsundstrum.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 1, 2015

@anievagomez can you elaborate? do you have other es6 assets that you want the TS compiler to transpile, or just es5 sources that you do not want to migrate but still want to code against?

@ldminoc
Copy link

ldminoc commented Oct 1, 2015

@mhegazy, it seems intuitive to me that any serious 'ambitious' application or enhancement to existing long-lived projects (incrementally transitioning to newer technology) would need both capabilities when considering adopting TypeScript, or face a massive uplifting exercise.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 1, 2015

@ldminoc i am interested in building an intuition of what a .js file "mean" in a typescript context. is it a reference (e.g. library, sources from that you do not intend to migrate to ts) that you would code against, or a source (i.e. an ES6 JS file that you want transpiled and bundled with your other .ts file outputs).

@forbesmyester
Copy link

A .ts file can just mean a JavaScript file with some ES6 features and
TypeScript's amazing editor support for guessing types and function
metadata. In fact it could even just be the latter if the code is well
written ES6...

At the moment I'm not sure TypeScript is the right choice for a project,
but some form of ES6 is probably the way to go, forcing me to change all my
extensions is too big an ask at this point.

Matt

On Thu, 1 Oct 2015 20:50 Mohamed Hegazy [email protected] wrote:

@ldminoc https://github.com/ldminoc i am interested in building an
intuition of what a .js file "mean" in a typescript context. is it a
reference (e.g. library, sources from that you do not intend to migrate to
ts) that you would code against, or a source (i.e. an ES6 JS file that you
want transpiled and bundled with your other .ts file outputs).


Reply to this email directly or view it on GitHub
#2302 (comment)
.

@kitsonk
Copy link
Contributor

kitsonk commented Oct 2, 2015

forcing me to change all my extensions is too big an ask at this point

You are right...

find . -name "*.js" -exec bash -c 'mv "$1" "$(sed "s/\.js$/.ts/" <<< "$1")"' - '{}' \;

is too much to ask... The whole project is doomed.

@forbesmyester
Copy link

I can write simple Bash too, that's not the issue.

Not all projects are single person project and some people really hate
TypeScript. Also How do I ensure that I'm not breaking everybody's syntax
highlighting and plugins on whatever editors they're using?

It'd be nice if I could use TypeScript without anyone else being effective,
if I'm careful, at least for a short period.

Matt

On Fri, 2 Oct 2015 09:33 Kitson Kelly [email protected] wrote:

forcing me to change all my extensions is too big an ask at this point

You are right...

find . -name "*.js" -exec bash -c 'mv "$1" "$(sed "s/.js$/.ts/" <<< "$1")"' - '{}' ;

is too much to ask... The whole project is doomed.


Reply to this email directly or view it on GitHub
#2302 (comment)
.

@kitsonk
Copy link
Contributor

kitsonk commented Oct 2, 2015

I can write simple Bash too, that's not the issue.

What is the issue then? The assertion was "forcing me to change all my extensions is too big an ask at this point"... Why?

@forbesmyester
Copy link

Not all projects are single person project and some people really hate
TypeScript. Also How do I ensure that I'm not breaking everybody's syntax
highlighting and plugins on whatever editors they're using?

Matt

On Fri, 2 Oct 2015 11:13 Kitson Kelly [email protected] wrote:

I can write simple Bash too, that's not the issue.

What is the issue then? The assertion was "forcing me to change all my
extensions is too big an ask at this point"... Why?


Reply to this email directly or view it on GitHub
#2302 (comment)
.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 2, 2015

@forbesmyester what you are looking for is #4793 then, correct? you want the TS developer experience (completion, highlighting, etc..) in an ES6 source file, without committing to using types, TS-specific-syntax, etc.. is this accurate?

@ldminoc
Copy link

ldminoc commented Oct 2, 2015

@mhegazy, it would be yes to both:

  1. es5 files treated as external modules, not requiring transpilation (but uplifted with typing support via .d.ts files)
  2. es6 files (files using es6 features) requiring transpilation to specified --target

Both are bundled but that will be the responsibility of a third-party tool such as webpack, hth.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 2, 2016

@mhegazy mhegazy closed this as completed Feb 2, 2016
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed In Discussion Not yet reached consensus labels Feb 2, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests