microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.16k stars 12.38k forks source link

Allow '--noEmit' to override 'emitDeclarationOnly' from config. #32380

Open mgcrea opened 5 years ago

mgcrea commented 5 years ago

Search Terms

Suggestion

Using "emitDeclarationOnly": true in your tsconfig.json prevents you to do typechecking only runs as running tsc --noEmit will throw the following error.

error TS5053: Option 'emitDeclarationOnly' cannot be specified with option 'noEmit'.

And the CLI does not look like to have any flag to bypass the error (eg. something like --noEmitDeclarationOnly).

I don't see a reason why a noEmit cli flag would not take precedence over the emitDeclarationOnly from the tsconfig.

Use Cases

With a project with a tsconfig.json set with emitDeclarationOnly and using another compiler like babel to produce the built javascript code, you want to be able to both:

Examples

https://github.com/mgcrea/node-influx-syslog

Checklist

My suggestion meets these guidelines:

SamB commented 5 years ago

Hmm. What could go wrong? The worst I can think of is if someone passes --emitDeclarationOnly on the command line when they already have "noEmit": true in tsconfig.json, if they already had declaration or composite set for some reason, then the simplest implementation approach would probably still end up emitting nothing ...

b2whats commented 5 years ago

+1

mskelton commented 4 years ago

+1

aryzing commented 4 years ago

@SamB seems reasonable, although to retain the general idea that CLI flags generally override configured behavior, cli flags should always override code emit settings from config, and noEmit should only override emit requests at the same level

For example, the noEmit flag overrides other flags that request code be emitted, and noEmit key in config overrides other keys in config that request code to be emitted. However, flags requesting code to be emitted will override noEmit key in config.

Pseudo-code for logic:

if (noEmit_flag) {
  do not emit anything
} else if (noEmit_flag && emitSomething_flag) {
  do not emit anything
} else if (noEmit_key && emitSomething_flag) {
  emit what was requested, cli flags always override 
} else if (noEmit_key && emitSomething_key) {
  do not emit anything
}
draperunner commented 3 years ago

FYI, this works:

tsc --noEmit --emitDeclarationOnly false
ekr3peeK commented 11 months ago

Why is this issue stale? I think that the request is a valid one, and many other plugins do the same. I am seconding @aryzing s comment, that cli flags should overwrite configuration flags, so that if I generally want to emit only declarations when compiling with typescript, I add that to the config, and otherwise, I run tsc with the --noEmit flag, when I am only typechecking.

Until that, @draperunner s workaround is okay, but I think that if cli parameters do not take precedence over the config parameters, this could lead to other strange bugs, which won't be as easily solvable as this one.