首页 > 其他分享 >TypeScript tsconfig.json declaration All In One

TypeScript tsconfig.json declaration All In One

时间:2023-03-11 11:24:14浏览次数:56  
标签:TypeScript utils xgqfrms ts module loader json declaration tsconfig

TypeScript tsconfig.json declaration All In One

.d.ts

tsconfig.json

{
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "./types"
  }
}

项目结构树

# tree
$ tree
typescript-demo
├── index.js
├── index.ts
├── package.json
├── tsconfig.json
└── types
    └── index.d.ts

https://www.typescriptlang.org/tsconfig#declarationDir

demos

{
  "compilerOptions": {
    "module": "CommonJS",
    // "module": "commonjs",
    // "module": "umd",
    // "module": "amd",
    // "module": "es6",
    // "target": "es6",
    "target": "es5",
    // "target": "es3",
    "sourceMap": true,
    "sourceRoot": "./src",
    "baseUrl": "./src",
    "outDir": "./dist/",
    "locale": "zh-CN",
    "noImplicitAny": true,
    "allowJs": true,
    "declaration": true,
    "declarationDir": "./types"
  },
  "type": "module",
  "include": [
    // include folder ✅
    "src/**/*",
  ],
  "exclude": [
    "node_modules",
    "types",
    "build",
    "dist",
    "build",
    "000-xyz/**/*",
    "test/**/*.spec.ts"
  ]
}


webpack 5 typescript loader

Could not find a declaration file for module 'loader-utils'. '/Users/xgqfrms-mm/Documents/github/webpack-loader/node_modules/loader-utils/lib/index.js' implicitly has an 'any' type.
Try npm i --save-dev @types/loader-utils if it exists or add a new declaration (.d.ts) file containing declare module 'loader-utils';ts(7016)

# 好使 ✅
# npm i --save-dev @types/loader-utils
$ npm i -D @types/loader-utils

// 不好使 ❌
declare module 'loader-utils';

image

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-04-22
 * @modified 2023-03-10
 *
 * @description webpack5 x typescript => webpack loader
 * @augments
 * @example
 * @link https://github.com/xgqfrms/webpack-loader
 *
 */

const log = console.log;

// log(`webpack5 x typescript => loader

标签:TypeScript,utils,xgqfrms,ts,module,loader,json,declaration,tsconfig
From: https://www.cnblogs.com/xgqfrms/p/17205522.html

相关文章