{ "compilerOptions": { "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ "module": "commonjs", /* Specify what module code is generated. */ "rootDir": "./src", /* Specify the root folder within your source files. */ "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ "sourceMap": true, /* Create source map files for emitted JavaScript files. */ "outDir": "./lib", /* Specify an output folder for all emitted files. */ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ "strict": true, /* Enable all strict type-checking options. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ } }
○ 安装@types/node 以支持 Node 的 ts 类型定义。
Web 项目
○ tsconfig.json 内容样例。
1 2 3 4 5 6 7 8 9 10 11 12
{ "compilerOptions": { "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ "module": "commonjs", /* Specify what module code is generated. */ "lib": ["dom", "esnext"] /* Specify library files to be included in the compilation. */, "jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */, "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ "strict": true, /* Enable all strict type-checking options. */ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ } }