microsoft / TypeScript

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

tsconfig.json exclude doesn't support specific file path #33526

Closed John0King closed 2 years ago

John0King commented 5 years ago

TypeScript Version: 3.6.2

Code

{
    "extends": "../tsconfig.base.json",
    "include": [
        "./src/**/*"
    ],
    "exclude": [
        "./src/Polyfills.ts",
        "./src/WebSocketTransport.ts",
        "./src/NodeHttpClient.ts",
        "./src/XhrHttpClient.ts"
    ]
}

Expected behavior:

tsc will ignore those files .

Actual behavior: image

RyanCavanaugh commented 5 years ago

I can't reproduce this locally. Here's my layout:

tsconfig.json
src/a.ts
src/b.ts <-- contains an error

tsconfig.json:

{
  "compilerOptions": {
  },
  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "./src/b.ts"
  ]
}

This compiles without error; changing "./src/b.ts" to "./src/x.ts" causes the error to be found as expected.

Can you provide more detail on how to reproduce the problem? Thanks!

John0King commented 5 years ago

@RyanCavanaugh I'm try port signalr to wechat miniprogram , this is my project https://github.com/John0King/WeChatApp.SignalR , and I know there will be many error in source file and becase I remove dom lib, but the there are two main probelm for me ,

  1. excluded file continue to show error for me (I'm going to comment all code in those file for temporary)
  2. I intall the "miniprogram-api-typings": "^2.8.3" with yarn , but It won't show it's decleration I figured this out
codechaotic commented 4 years ago

I had a similar issue. In my case one of the files in the source was being auto-generated using ts-pegjs and didn't comply with the strict typescript. The rest of my files did, so I wanted the compiler to hush up about the errors in that file. I couldn't change the file, so I tried putting the file in the exclude list. But the errors still occurred.

As it turns out, I was misunderstanding the intended behavior of the exclude option and thought that it would silence errors from files that I wanted it ignore. In the tsconfig docs it notes regarding the exclude option that

Any files that are referenced by files included via the "files" or "include" properties are also included. Similarly, if a file B.ts is referenced by another file A.ts, then B.ts cannot be excluded unless the referencing file A.ts is also specified in the "exclude" list.

Since my generated file was still being imported somewhere in my source, typescript was disregarding my attempt to exclude it. Perhaps your files are still being imported somewhere too? I hope this help.

chrisdugne commented 2 years ago

Hi @codechaotic , thanks for your input, I have the exact same issue: what workaround do you use to ignore the error in the generated file ?