K
TypeScript 配置
创建于:2025-07-26 15:06:11
|
更新于:2026-06-18 17:31:20
配置项说明
compilerOptions编译器选项,包含多个子选项来控制 TypeScript 编译行为。
include指定要包含在编译中的文件或目录。
exclude指定要排除在编译之外的文件或目录。
files明确指定要编译的文件列表。
extends继承另一个配置文件的配置。
references用于配置项目引用,以支持多项目构建。
typeRoots指定 TypeScript 应该包含的类型声明文件的目录。
types指定需要包含的类型声明包。
baseUrl用于解析非相对模块名称的基准目录。
paths模块名到基准目录的映射,配合 baseUrl 使用。
rootDir用于控制输出目录结构的根目录。
outDir指定编译输出的目录。
sourceMap生成对应的 .map 文件,便于调试。
declaration生成对应的 .d.ts 类型声明文件。
removeComments从输出的文件中移除注释。
noEmit不生成输出文件,仅进行类型检查。
strict启用所有严格类型检查选项。
esModuleInterop允许对 CommonJS 和 ES 模块之间进行互操作。
skipLibCheck跳过对库文件的类型检查。
target指定 ECMAScript 目标版本。
module指定模块系统。

alias

yarn add @types/node -D

tsconfig.json
{
  "compilerOptions": {
    /* path */
    "baseUrl": "./",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}

global.d.ts

global.d.ts
// 图片类型声明
declare module "*.png";
declare module "*.jpg";
declare module "*.jpeg";
declare module "*.gif";
declare module "*.svg";
declare module "*.webp";
 
// 库类型声明 (有些垃圾库没有类型声明)
declare module "cn-lib";
 
// react css
import type * as CSS from 'csstype';
 
declare module 'csstype' {
  interface Properties {
    // Add a missing property
    WebkitRocketLauncher?: string;
 
    // Add a CSS Custom Property
    '--theme-color'?: 'black' | 'white';
 
    // Allow namespaced CSS Custom Properties
    [index: `--theme-${string}`]: any;
 
    // Allow any CSS Custom Properties
    [index: `--${string}`]: any;
 
    // ...or allow any other property
    [index: string]: any;
  }
}
我也是有底线的 🫠