Best practice to setup tsconfig “files” vs “include”?

There are two examples of tsconfig.json presented on the official website of TypeScript,—one with "files" property, another one with "include" and "exclude" properties specified:

Using the "files" property

{
    "compilerOptions": {
        // irrelevant
    },
    "files": [
        "core.ts",
        "sys.ts",
        "types.ts",
        "scanner.ts",
        "parser.ts",
        "utilities.ts",
        "binder.ts",
        "checker.ts",
        "emitter.ts",
        "program.ts",
        "commandLineParser.ts",
        "tsc.ts",
        "diagnosticInformationMap.generated.ts"
    ]
}

Using the "include" and "exclude" properties

{
    "compilerOptions": {
        // irrelevant
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}

So, basically, "files" is used to specify separate files directly by their path, while "include" and "exclude" is used to target collections or groups of files or folders etc.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)