TypeScript: Is it really truly wrong to have an empty array for `files` in the config?

TypeScript Version: 2.1.4

Code

$ mkdir ts-error
$ cd ts-error
$ npm install typescript@2.1.4
$ echo '{"files": []}' > tsconfig.json
$ ./node_modules/.bin/tsc
error TS18002: The 'files' list in config file '/Users/danfuzz/testing/ts/tsconfig.json' is empty.

Expected behavior:

tsc doesn’t complain about not actually getting asked to compile anything.

Actual behavior:

The error as noted.

Context:

It is of course pretty silly to actually use the TS compiler on the commandline and with an actual tsconfig.json in the way demo’ed here. However, in the case of using the ts-loader module to hook up the TS compiler to Webpack, this is how it sets itself up. (I’m just a user of ts-loader, not a developer of it, so please take this with a grain of salt.) AIUI ts-loader sets up the basic config with an empty files, and then makes separate calls to compile each file it’s asked to, one at a time. This arrangement worked as of typescript version 2.0.10, but it broke as of 2.1.4.

I also filed https://github.com/TypeStrong/ts-loader/issues/405 on ts-loader. It’s not clear to me what the best way to address the issue is.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 41 (18 by maintainers)

Most upvoted comments

I agree with much of the sentiment here. Consider another case: creating a new project and configuring typescript is often the first step for many teams. The notion that their initial project will throw an exception when no ts has been written yet is jarring. The absence of anything to compile shouldn’t throw an exception, it should succeed with ease.

Maybe this could be downgraded to a warning?

We’ll be allowing zero-input compilations if a references array is present in tsconfig.json (even if it’s empty)

Hi, I’m trying out the Salsa language service in an ASP.NET MVC 5 project where everything is still JavaScript, but I enabled Salsa just to have IntelliSense for e.g. jQuery and Kendo via @types packages. I added a tsconfig in order to exclude all the JavaScript libraries. I want the the language service to look only at my JS code and the TS definitions in @types.

So, in this IntelliSense-only scenario, the officially recommended way of making the compiler happy is to add an empty dummy file to the project because the “include” array must not be empty, right? Or is there an other way to configure the language service just for IntelliSense without having to deal with such TS compiler issues?

It seems like it still does this even if include is non-empty.

I understand that this change in behavior was intentional and for good reason, like, if you aren’t intentionally asking not to compile anything, then it’s probably bad if the compiler doesn’t compile anything and also doesn’t let you know.

So, by way of suggestion, maybe there can be an explicit config file flag that indicates “really, zero files are being listed intentionally.”