typescript 配置

Last updated on November 22, 2024 pm

🧙 Questions

tsconfig.json 的作用
当我们用ts进行写代码的时候
需要用tsc命令打包编译 tsc xxx –config xxx
如果我们把所有的配置文件写进tsconfig.json 就可以免去每次tsc敲很长的命令

☄️ Ideas

{
    // compilerOptions 编译时配置项 
    "compilerOptions": {
        //  设置root路径
       "baseUrl": "./",
        // 映射路径    
        "paths": {
            "react-keycap": ["components/index.tsx"],
            "react-keycap/es/*": ["components/*"]
        },
        // 允许使用 import * as xx from xx
        "allowSyntheticDefaultImports": true,
        // 允许null值 
        "strictNullChecks": true,
        "alwaysStrict": true,
        "allowJs": true,
        "noUnusedParameters": true,
        "noUnusedLocals": true,
        "noImplicitAny": false, // 运行使用any,any不报错
        "skipLibCheck": true,
        "jsx": "react",
        "target": "esnext",
        "outDir": "./es",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "lib": [
            "dom",
            "esnext"
        ],
        "declaration": true,
        "declarationDir": "./es"
    },
    // 引入需要编译的文件路径
    "include": [
        "./components"
    ],
    // 排除那些文件不再编译
    "exclude": [
        "node_modules",
        "lib",
        "es",
        "**/_test_"
    ]
}

typescript 配置
https://ispong.isxcode.com/vue/typescript/typescript 配置/
Author
ispong
Posted on
May 8, 2022
Licensed under