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

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.

主站蜘蛛池模板: 铜梁县| 轮台县| 阜宁县| 白朗县| 枣阳市| 聊城市| 新巴尔虎右旗| 都江堰市| 禹城市| 望江县| 房产| 宁乡县| 义乌市| 察隅县| 大港区| 京山县| 中宁县| 双城市| 子长县| 天台县| 清新县| 尖扎县| 梅河口市| 始兴县| 泸州市| 高邑县| 长子县| 南安市| 南康市| 宜兰县| 兴安盟| 七台河市| 嫩江县| 和顺县| 湄潭县| 潢川县| 当涂县| 神农架林区| 曲阜市| 旌德县| 平阳县|