-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Should tsc file.js
build a file with the "compilerOptions" in TypeScript's config. Or should it compile a file and ignore the config?
#29241
Comments
The error message says you should be targeting |
@fatcerberus I have a sample repo with it, in that repo i'm doing es2018 for lib, but you can try es2015 same thing. |
Just a hunch, have you tried using lowercase for |
It is lower case, no joy. It's also confirmed by the rxjs guys and the stackoverflow commenter. Nothing that uses promises works on node 11 |
oh okay - I see, the issue is when the typescript compiler is run on node 11, not when targeting node 11. My bad. |
So I tried to reproduce this using the exact tsconfig, dependencies, and sample code as in the SO question... and it seems to work fine on my end. Node.js version is 11.6.0.
|
Did you pull down my repository run npm install and then try to tsc the file? I'm confused, you say this
Which is true, and then you say " it seems to work fine on my end. Node.js version is 11.6.0." |
Yeah, that was before I tested it - that was just stating I understood why you mentioned the node version. |
I don't know what else to say, I got the prob. Guy on SO and on RXJS question got the prob. Repo is simple works (to show the problem) with the latest version of all tools. It's giving that error on running tsc on my box (running Linux). |
This is the line that's problematic for you, this is working?
|
Yeah, that works, as does:
v11.5 because I switched machines--still Node 11 though. Tested on both Windows and Linux (Ubuntu 16.04, Node.js installed from snap). Only thing I can think of is you're somehow picking up a stale tsconfig.json from elsewhere. |
no idea what npx does, or what it's doing differently can you just run |
It's the same thing - |
No idea, all I know is it's erroring with me and I'm not using any special layer so I'm trying to keep it simple and figure out why it's not erroring for you, and I'm thinking your npx is doing something. |
Nope, here's the exact issue - you're telling tsc to transpile a single file. In that case it ignores the tsconfig.json and just transpiles the file in a vacuum, using all defaults for the tsconfig fields. Since there is no |
What you want to do is just run |
This behavior, by the way, is documented:
|
Wow, even if documented that's extremely counter intuitive. I can't think of any program that ignores the configuration file when given an argument that isn't explicitly either conflicting with the configuration file, or demanding to override it. That's not a good user interface at all. Git and NPM being two examples that don't behave in that way that typescript users are likely to be using in the same project. |
The use case here being
At the absolute least I would expect |
It makes sense to me at least - you either tell it to compile a whole project file, or you pass one or more source files and specify the options on the command line. Everything you can specify in tsconfig.json has a corresponding command-line option. It would be probably be bad if it used the tsconfig when specifying files on the command line - since then if you used tsc in, say, a shell script, the behavior of the script would change depending on whether the CWD contained a tsconfig. |
Essentially the tsconfig is a “build script” - you tell tsc to use that instead of specifying everything you want to do on the command line. It’s not a “compiler preferences” file (admittedly the naming of “tsconfig” is a bit confusing in that regard), it’s a self-contained project in itself, like what .vcproj is for MSVC. |
Basically: think of tsconfig.json as a makefile, and |
Isn't that how everything works though?
None of them forget about their config file when you provide an option. They simply override that option and use the config file to create the execution environment for the command. I understand what you're talking about but this is the only utility that works in this fashion -- where providing an argument means it forgets about the config file. I want the config file to configure TSC for the project. Not to specify the exact item i'm wanting to compile. It just intuitive to me that the working directory be significant, especially if there is a config file inside it and not only if there are no arguments provided to the program. |
Let me make it clear: What you’re essentially asking for is analogous to wanting |
What you may be able to do is (not tested):
|
Not exactly, because GCC and make are separate; there is a distinction there so I would never expect gcc to accept a configuration file anyway. But tsc does with the So with make if you have a basic Makefile,
And you run
It still uses the make file. It doesn't forget it and act like a compiler. It just builds instead |
Does it seem intuitive to you to say that the default for |
Using the above analogy: It just so happens that, for convenience, the specific case of |
I understand how things are, now that you've explained them and did immediately on my first response here. I just find that entirely unintuitive and I imagine I'm in the majority here. You've severed tsc into two modes, neither of which are apparent to the user and used those two modes to justify a different user interface. I wasn't aware that I was supposed to
I'll just leave it off with this, because I'm honestly just trying to provide some guidance to build a better system. Ask some people who do NOT know the default behavior this question
Just for fun https://twitter.com/TheEvanCarroll/status/1080899909522477061 (maybe I am in the minority) |
I’ll agree with you that the “project builder” should probably be a separate tool (tsmake or something), but practically speaking, since I assume it was a conscious design decision not to have two distinct tools, how would you make |
Wouldn't you want to follow the lead of most all the other tools (eslint, babel, etc) and have an explicit CLI opt-out for avoiding the config file? In other words, "gcc" usage is nowhere near the common case, and seems surprising to most users, so it seems like a poor choice of default. |
In any case, I don’t think this can be changed now without breaking peoples’ build environments, which would be bad considering how TypeScript’s release cycle seems to work (every major or minor version supersedes the last). But I’ll duck out at this point and let actual TypeScript team members chime in if they want before I accidentally make a fool of myself. 😄 |
Would you consider changing the title of the issue to better reflect the ongoing conversation, to provide a better summary and be more convenient to find? For an example, “Inconsistent tsc behavior with and without file parameters”. @EvanCarroll @weswigham |
lib
compiler option to es2015 or latertsc file.js
build a file with the "compilerOptions" in TypeScript's config. Or should it compile a file and ignore the config?
Another use case: we have a pre-commit hook which runs Even without implicit using (maybe this isn't that issue where I should post this comment, but my opinion is that tsc should use compiler options from a config while compiling only one file) |
Thanks for your help all. Problem solved here. |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow. |
@DanielRosenwasser @RyanCavanaugh It is very disappointing this hasn't been taken further into consideration. This is how 98% of javascript developers expect |
Please reopen; nonhumans closing issues is exceedingly user-hostile. |
Allowing to override |
This is already supported!
I will close this myself to help 😉 |
This is the intended behavior because we don't want to break thousands of |
You can add
What about allowing to pass a list of files along with Also, what's about compiler options which cannot be passed via CLI such |
See also #27379. I think there's also another issue where people expect to be able to augment the file list in this manner.
I think allowing some way of specifying additional tsconfig files (probably in a "config only" mode) would be a very reasonable suggestion. I know some teams are effectively doing this by auto-generating tsconfig files in their build scripts; it'd be nice to make that kind of automation unnecessary. |
This is exactly what I was trying to do and it doesn't work for me. I will look at versions for a new update if you're saying this is supported already. |
With Node v11.6.0, and TSC, 3.2.2, I am getting
When I run
Using
@types/node
This is a bug push up from rxjs ReactiveX/rxjs#4448
You can see the issue documented at https://stackoverflow.com/questions/54014405/ts2585-promise-only-refers-to-a-type-but-is-being-used-as-a-value-here
The text was updated successfully, but these errors were encountered: