TypeStrong / fork-ts-checker-webpack-plugin

Webpack plugin that runs typescript type checker on a separate process.
MIT License
1.95k stars 240 forks source link

Type checking only imported modules #784

Closed dglazkoff closed 1 year ago

dglazkoff commented 1 year ago

I have test files that used jest as test library. jest was installed as dev depedencies. When I start production build using babel/preset-typescript and fork-ts-checker-webpack-plugin I get errors, that ts can not find jest. But my test files do not imported and do not execute. How can I say, that fork-ts-checker-webpack-plugin must not to type check not imported files in production build.

piotr-oles commented 1 year ago

Does tsc --noEmit command report type error?

piotr-oles commented 1 year ago

TypeScript is designed to operate on a project basis, using a list of files rather than a dependency graph for type-checking. It is not something that can be altered in this plugin. However, you can utilize the configOverwrite.exclude option to exclude test files in the plugin :)

mikevoets commented 3 months ago

If anyone is wondering how to do this, this is what I did:

// webpack.development.config.js

const tsConfig = require('tsconfig.json');

const webpackConfig = generateWebpackConfig({
  plugins: [
    new ForkTSCheckerWebpackPlugin({
      typescript: {
        configOverwrite: {
          exclude: [...tsConfig.exclude, '**/*.test.ts*'],
        },
      },
    })
  ],
});