Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore some files when running type checking some files using tsc

Tags:

typescript

I would like to ignore some files when type checking some files using tsc and cannot figure out how this is done in TypeScript. Tools like eslint or flow allow special comments in the source files that allow to control the compiler.

like image 868
doberkofler Avatar asked Dec 28 '18 18:12

doberkofler


People also ask

How do I ignore files in TypeScript?

Use // @ts-ignore to ignore the type checking errors on the next line in a TypeScript file. If you use a linter, you might have to add a comment to also suppress linting errors when using ts-ignore - // eslint-disable-next-line @typescript-eslint/ban-ts-comment . Copied!

How do I ignore TypeScript check?

Use the // @ts-ignore comment to disable type checking for a line in TypeScript. The comment disables type checking for the next line. If you use a linter, you might need to disable it for the line on which you use the // @ts-ignore comment. Copied!

Does TSC use Tsconfig?

Running tsc locally will compile the closest project defined by a tsconfig. json , you can compile a set of TypeScript files by passing in a glob of files you want.

What does the TSC command do?

The tsc command envokes the TypeScript compiler. When no command-line options are present, this command looks for the tsconfig. json file. If no tsconfig.


1 Answers

In individual files, you can ignore specific lines by adding // @ts-ignore on the preceding line.

more about it here (// ts-ignore does not work with .ts files however as of now)

and exclude files/folders using glob patterns in your tsconfig.json as below as long long as they aren't imported in other files such as in the case of independent unit test files and the like

{
    "exclude": [
        "**/*.spec.ts"
    ]
}

more about that, here

like image 74
c_thane Avatar answered Oct 09 '22 10:10

c_thane