Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude type checking for files which matches with exclude option from tsconfig #2258

Closed
changchangge opened this issue Jan 7, 2021 · 2 comments
Labels
🚀 Feature Request new suggested feature

Comments

@changchangge
Copy link

TypeScript Version:4.1.3
ts-jest Version:26.4.4

Code

tsconfig.json

{
  "compilerOptions": {
    "sourceMap": false,
    "module": "commonjs", 
    "noImplicitAny": true, 
    "removeComments": false,
    "moduleResolution":"node",
    "baseUrl": ".",  
    "target": "es6", 
    "outDir": "./lib",
    "declaration": true,
    "strict": true,
  },
  "include": ["src"],
  "exclude": ["node_modules","tests"]
}

jest.config.js

module.exports = {
  roots: ['<rootDir>/tests'],
  globals: {
    'ts-jest': {
      tsconfig: 'tsconfig.json',
    },
  },
  transform: {
    '^.+\\.ts?$': 'ts-jest',
  },
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
  testEnvironment: 'node',
  collectCoverageFrom: ['<rootDir>/src/**/*'],
  coveragePathIgnorePatterns: ['<rootDir>/node_modules', '<rootDir>/tests'],
  verbose: true,
};

When I run tsc, it is ok. But if I run jest to test,it is failed.

Expected behavior:

Avoid and exclude tests ts files.

Actual behavior:

It check ts files in the tests folder which has been excluded.

Workaround:

But if a restart VS then i will see the same behavior.

error:

● Test suite failed to run

tests/tag2.test.ts:5:22 - error TS7006: Parameter 'state' implicitly has an 'any' type.

Here is my project:
https://github.com/changchangge/simple-redux/tree/tag2

I hope that someone can help me , thanks!

@changchangge changchangge added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jan 7, 2021
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 7, 2021

Hi, for ts-jest, we always do type checking for all .ts files by default regardless what is defined in exclude and it has been like that. Workaround is to use https://kulshekhar.github.io/ts-jest/docs/options/diagnostics

I think it does make sense to follow the real purpose of those config options.

I will convert this to feature request instead.

@ahnpnl ahnpnl added 🚀 Feature Request new suggested feature and removed Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jan 7, 2021
@ahnpnl ahnpnl changed the title ts-config.json exclude is not working with ts-jest exclude type checking for files which matches with exclude option from tsconfig Jan 7, 2021
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 7, 2021

I've checked. Actually we can't use exclude for type checking. exclude option is tsconfig does 3 things:

  • Exclude files from TypeScript Program for module resolution
  • Exclude files from compiling
  • Exclude files from type checking

ts-jest makes use of TypeScript Program to compile codes and type checking. This process is an incremental on-demand process, it's not the same like normal behavior of tsc. ts-jest behavior is partially similar to tsc to be able to work with Jest.

Therefore, it is not possible to use exclude to exclude files from type checking because that will break compilation process.

I will close this issue as we use diagnostics option as alternative way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 Feature Request new suggested feature
Projects
None yet
Development

No branches or pull requests

2 participants