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

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.

主站蜘蛛池模板: 云安县| 山阳县| 巍山| 深圳市| 鲁甸县| 武清区| 肇庆市| 从江县| 万全县| 三门县| 那曲县| 广灵县| 奉贤区| 龙泉市| 芷江| 鸡西市| 明水县| 交城县| 白山市| 鸡泽县| 绿春县| 桑植县| 余干县| 曲周县| 文山县| 淮南市| 广平县| 威远县| 马尔康县| 诏安县| 高清| 泸定县| 大足县| 望城县| 高尔夫| 资溪县| 新和县| 靖安县| 和平区| 佛冈县| 静安区|