awesome-typescript-loader icon indicating copy to clipboard operation
awesome-typescript-loader copied to clipboard

Awesome typescript loader not respecting "exclude" property for type checking

Open IAMtheIAM opened this issue 8 years ago • 11 comments
trafficstars

I tried every combination I can think of any awesome typescript loader will not respect the exclude property in tsconfig.json

   "exclude": [
      "compiled",
   ],
   "exclude": [
      "compiled/*",
   ],
   "exclude": [
      "**/compiled/*",
   ],

Full config

{
   "compilerOptions": {
      "allowSyntheticDefaultImports": true,
      "baseUrl": ".",
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "lib": [
         "dom",
         "es6"
      ],
      "moduleResolution": "node",
      "noStrictGenericChecks": true,
      "outDir": "lib",
      "paths": {},
      "pretty": true,
      "sourceMap": true,
      "sourceRoot": ".",
      "strictNullChecks": false,
      "target": "es5",
      "typeRoots": [
         "./node_modules/@types"
      ],
      "types": [
         "core-js",
         "hammerjs",
         "lodash",
         "materialize-css",
         "node",
         "jasmine",
         "source-map",
         "uglify-js",
         "webpack"
      ]
   },
   "exclude": [
      "./node_modules",
      "./compiled",
      "./wwwroot",
      "../backend-nodejs",
      "./src/**/*.e2e.ts",
      "./src/**/*.spec.ts",
      "./config/protractor.config.ts"
   ],
   "filesGlob": [
      "src/**/*.ts",
      "src/custom-typings.d.ts",
      "src/types/require.d.ts"
   ],
   "atom": {
      "rewriteTsconfig": false
   },
   "awesomeTypescriptLoaderOptions": {
      "forkChecker": true,
      "resolveGlobs": true,
      "useCache": false
   },
   "buildOnSave": false,
   "compileOnSave": false
}

It still checks the compiled folder for type errors, even though this folder is not referenced in my current webpack build. What is the proper way to exclude a folder from type checking?

IAMtheIAM avatar Sep 12 '17 18:09 IAMtheIAM

Is this repo still being maintained? lots of unanswered issues and no commit for 6 weeks. Just wondering if I should switch to ts-loader, last commit 22 hours ago.

IAMtheIAM avatar Sep 25 '17 16:09 IAMtheIAM

In my case it's not ignoring node_modules :( That gives me

[at-loader] Checking started in a separate process...

[at-loader] Checking finished with 11 errors
[at-loader] ./node_modules/@angular/cdk/table/typings/table.d.ts:38:22 
    TS2420: Class 'CdkTable<T>' incorrectly implements interface 'CollectionViewer'.
  Types of property 'viewChange' are incompatible.
    Type 'BehaviorSubject<{ start: number; end: number; }>' is not assignable to type 'Observable<{ start: number; end: number; }>'.
      Types of property 'lift' are incompatible.
        Type '<R>(operator: Operator<{ start: number; end: number; }, R>) => Observable<{ start: number; end: n...' is not assignable to type '<R>(operator: Operator<{ start: number; end: number; }, R>) => Observable<R>'.
          Type 'Observable<{ start: number; end: number; }>' is not assignable to type 'Observable<R>'.
            Type '{ start: number; end: number; }' is not assignable to type 'R'. 

[at-loader] ./node_modules/@angular/material/chips/typings/chip-list.d.ts:27:22 
    TS2420: Class 'MdChipList' incorrectly implements interface 'MdFormFieldControl<any>'.
  Types of property 'stateChanges' are incompatible.
    Type 'Subject<void>' is not assignable to type 'Observable<void>'.
      Types of property 'lift' are incompatible.
        Type '<R>(operator: Operator<void, R>) => Observable<void>' is not assignable to type '<R>(operator: Operator<void, R>) => Observable<R>'.
          Type 'Observable<void>' is not assignable to type 'Observable<R>'.
            Type 'void' is not assignable to type 'R'. 

[at-loader] ./node_modules/@angular/material/input/typings/input.d.ts:15:22 
    TS2420: Class 'MdInput' incorrectly implements interface 'MdFormFieldControl<any>'.
  Types of property 'stateChanges' are incompatible.
    Type 'Subject<void>' is not assignable to type 'Observable<void>'. 

[at-loader] ./node_modules/rxjs/Subject.d.ts:16:22 
    TS2415: Class 'Subject<T>' incorrectly extends base class 'Observable<T>'.
  Types of property 'lift' are incompatible.
    Type '<R>(operator: Operator<T, R>) => Observable<T>' is not assignable to type '<R>(operator: Operator<T, R>) => Observable<R>'.
      Type 'Observable<T>' is not assignable to type 'Observable<R>'.
        Type 'T' is not assignable to type 'R'. 

naivefun avatar Sep 27 '17 00:09 naivefun

@naivefun post your entire .tsconfig file for review

IAMtheIAM avatar Sep 27 '17 15:09 IAMtheIAM

I observed this issue, too. I'd like to use "exclude" in my .tsconfig. My project is still fairly small, so I managed to work around the issue with an "include" configuration instead:

{
  ...
  "include": [
    "./src/**/*"
  ],
  "awesomeTypescriptLoaderOptions": {
    "reportFiles": [
      "./src/**/*"
    ]
  }
}

This tells at-loader to only nag about errors in the listed files/directories (src is where I keep all my Javascript and Typescript sources).

kreba avatar Sep 28 '17 08:09 kreba

I'm seeing the same issue, although it's flakey. It appears to only occur when at-loader chooses to fork the compiler to do type-checking in a separate process.

elldritch avatar Oct 09 '17 09:10 elldritch

Please use reportFiles option

s-panferov avatar Nov 01 '17 06:11 s-panferov

@s-panferov So exclude does not work? Please example reportFiles

IAMtheIAM avatar Nov 06 '17 16:11 IAMtheIAM

I'm seeing the same issue!

monkingxue avatar Nov 06 '17 17:11 monkingxue

@IAMtheIAM From looking at the README, it seems you can edit the loader options in your webpack config to only emit TS errors for the files that match a glob. Something like this:

    rules: [{
        test : /\.ts$/,
        use  : {
            loader : 'awesome-typescript-loader',
            options : {
                reportFiles: [
                    'src/**/*.{ts,tsx}'
                ]
            },
        },
    }]

This results in no change to the actual behaviour you expect from the loader and webpack, but squelches the TypeScript checker errors for anything outside src/.

Of course, if your node_modules is in src/ this gets trickier. Globs for excluding a directory are not so pretty:

'{,!(node_modules)/}**/*.{ts,tsx}'

That second one is untested, but I think it should work.

(I know I'm replying to a comment that's almost a year old, but this thread was top of the Google results when I was trying to solve the same problem, so I'm providing the example for those who come later)

arch-daemone avatar Sep 28 '18 12:09 arch-daemone

@IAMtheIAM From looking at the README, it seems you can edit the loader options in your webpack config to only emit TS errors for the files that match a glob. Something like this:

    rules: [{
        test : /\.ts$/,
        use  : {
            loader : 'awesome-typescript-loader',
            options : {
                reportFiles: [
                    'src/**/*.{ts,tsx}'
                ]
            },
        },
    }]

This results in no change to the actual behaviour you expect from the loader and webpack, but squelches the TypeScript checker errors for anything outside src/.

Of course, if your node_modules is in src/ this gets trickier. Globs for excluding a directory are not so pretty:

'{,!(node_modules)/}**/*.{ts,tsx}'

That second one is untested, but I think it should work.

(I know I'm replying to a comment that's almost a year old, but this thread was top of the Google results when I was trying to solve the same problem, so I'm providing the example for those who come later)

Thank you so much!And do you know why the tsconfig.json file doesn't work ? thanks again!

Enzo1994 avatar Dec 01 '18 17:12 Enzo1994

@Enzo1994 Not a clue! I've got nothing to do with at-loader, I'm just a user of it, like you.

I would think, though, that you could put the reportFiles option in your tsconfig.json (in awesomeTypescriptLoaderOptions) instead of inside your webpack config, and it would work the same. You're supposed to be able to do that for all loader options. See the code snippet in kreba's comment above.

arch-daemone avatar Dec 03 '18 09:12 arch-daemone