microsoft / TypeScript

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

tsc sometimes doesn't respect "include" in tsconfig.json #19798

Closed Zarel closed 6 years ago

Zarel commented 6 years ago

TypeScript Version: 2.6.1, 2.7.0-dev.201xxxxx

Code

Unfortunately, this error disappears when I try to construct a simple self-contained test-case (most TypeScript errors I encounter work like this, which makes debugging them really weird).

But you can reproduce this with:

git clone https://github.com/Zarel/Pokemon-Showdown
cd Pokemon-Showdown
git checkout 28cb849
npm i
tsc

Expected behavior:

No errors

Actual behavior:

punishments.js(1135,10): error TS1005: '{' expected.

This is unexpected because punishments.js is explicitly not one of the files included in "include" in tsconfig.json. Even explicitly adding "exclude": ["punishments.js"] doesn't make the error disappear.

I thought maybe I was using the wrong syntax? But when I copied the tsconfig.json to a new project, suddenly the "include" setting was being respected again (this is what I mean by "this error disappears when I try to construct a simple self-contained test-case").

Zarel commented 6 years ago

...never mind, I figured it out.

(punishments.js was being required by dev-tools/globals.ts)

Zarel commented 6 years ago

(On third thought, commenting out the relevant line of dev-tools/globals.ts doesn't make the error disappear, either; I'm confused again.)

mhegazy commented 6 years ago

The compiler picks up imports from your files, not just include/exclude, see https://github.com/Microsoft/TypeScript/wiki/FAQ#why-is-a-file-in-the-exclude-list-still-picked-up-by-the-compiler

Zarel commented 6 years ago

Yes, but if I remove the import, it's still giving the same error message.

Zarel commented 6 years ago

...okay, it's working now. There was a stray input elsewhere.

Zarel commented 6 years ago

...I'm still unclear on what's making the error message appear. It would probably be useful to be able to ask TypeScript what file is importing the file.

I was able to discover that chat-commands is importing punishments (and removing that import suppresses that error), but not what's importing chat-commands

mhegazy commented 6 years ago

...I'm still unclear on what's making the error message appear. It would probably be useful to be able to ask TypeScript what file is importing the file.

use tsc --listFiles to know what files are included in your compilation, and tsc --traceResolution to know why they were included.

Zarel commented 6 years ago

Thanks!