官术网_书友最值得收藏!

Specifying files for compilation

There are several ways to tell the TypeScript compiler which files to process. The simplest method is to explicitly list the files in the files field:

{
"compilerOptions": {
...
},
"files": ["product.ts", "orderDetail.ts"]
}

However, that approach is difficult to maintain as our code base grows. A more maintainable approach is to define file patterns for what to include and exclude with the include and exclude fields.

The following example looks at the use of these fields:

  1. Let's add the following include fields, which tell the compiler to compile TypeScript files found in the src folder and its subfolders:
{
"compilerOptions": {
...
},
"include": ["src/**/*"]
}
  1. At the moment, our source files aren't in a folder called src, but let's run a compile anyway:
tsc
  1. As expected, we get No inputs were found in the config file... from the compiler.

Let's create an src folder and move orderDetail.ts into this folder. If we do a compile again, it will successfully find the files and do a compilation.

So, we have lots of options for adapting the TypeScript compiler to our particular situation. Some options, such as --noImplicitAny, force us to write good TypeScript code. We can take the checks on our code to the next level by introducing linting into our project, which we'll look at in the next section.

主站蜘蛛池模板: 电白县| 怀安县| 兰考县| 班戈县| 金湖县| 新乡市| 葫芦岛市| 芦山县| 清水县| 尼木县| 庐江县| 扶沟县| 桂林市| 屯门区| 阿瓦提县| 黑山县| 呼和浩特市| 西乌珠穆沁旗| 大悟县| 十堰市| 饶河县| 板桥市| 册亨县| 石泉县| 襄城县| 赤峰市| 靖边县| 虞城县| 涿州市| 岳阳县| 游戏| 古蔺县| 辽中县| 麻栗坡县| 嘉鱼县| 平安县| 仙桃市| 徐水县| 淳化县| 涟水县| 韶关市|