@definitelytyped/dts-critic

中文文档
0.1.38发布于 2026/11/12MITTypeScriptCommonJS近 30 天下载 3.6万

Checks a new .d.ts against the Javascript source and tells you what problems it has

原始使用文档
文档目录4 节
  1. Mode
  2. Npm declaration
  3. Non-npm declaration
  4. Testing

dts-critic

Checks a new dts against the Javascript sources and tells you what problems it has.

Usage

Build the program:

$ npm run build

Run the program using node:

$ node dist/index.js --dts=path-to-d.ts [--js=path-to-source] [--mode=mode] [--debug]

If the d.ts path is to a file named index.d.ts, the name of the directory will be used as the package name instead. For example ~/dt/types/jquery/index.d.ts will use jquery as the name.

path-to-source is optional; if you leave it off, the code will check npm for a package with the same name as the d.ts.

Mode

You can run dts-critic in different modes that affect which checks will be performed:

  1. name-only: dts-critic will check your package name and DefinitelyTyped header (if present) against npm packages. For example, if your declaration is for an npm package called 'cool-js-package', it will check if a package named 'cool-js-package' actually exists in npm.

  2. code: in addition to the checks performed in name-only mode, dts-critic will check if your declaration exports match the source JavaScript module exports. For example, if your declaration has a default export, it will check if the JavaScript module also has a default export.

Current checks

Npm declaration

If your declaration is for an npm package:

  1. An npm package with the same name of your declaration's package must exist.
  2. If your package has a Definitely Typed-conforming package.json, the npm package's version must match your version.
  3. If you are running under code mode, your declaration must also match the source JavaScript module.

Non-npm declaration

If your declaration is for a non-npm package (in other words, if your declaration has a Definitely Typed-conforming package.json with "nonNpm": true):

  1. An npm package with the same name of your declaration's package cannot exist.
  2. If you are running under code mode and a path to the JavaScript source file was provided, your declaration must also match the source JavaScript module.

Planned work

  1. Make sure your module structure fits the source.
  2. Make sure your exported symbols match the source.
  3. Make sure your types match the source types???
  4. Download source based on npm homepage (if it is github).

Note that for real use on Definitely Typed, a lot of these checks need to be pretty loose.

Contributing

Testing

The tests use Node.js's test runner against compiled JavaScript. From the monorepo root, build all packages and tests, then run the dts-critic tests:

pnpm build
pnpm test packages/dts-critic

Rebuild after changing source files or tests.

版本与发布记录

@definitelytyped/dts-critic 共发布 171 个版本,首次发布于 2021/12/02;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.1.38latest2026/11/12今天
0.1.372026/11/047 天前
0.1.352026/10/2221 天前
0.1.332026/07/213 个月前
0.1.322026/07/094 个月前
0.1.312026/06/164 个月前

其他发布通道:next → 0.0.172-next.0。

关于 @definitelytyped/dts-critic 的常见问题

@definitelytyped/dts-critic 是什么?

Checks a new .d.ts against the Javascript source and tells you what problems it has

如何安装 @definitelytyped/dts-critic?

在项目目录运行 npm install @definitelytyped/dts-critic,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:typescript(<7)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@definitelytyped/dts-critic 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@definitelytyped/dts-critic 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@definitelytyped/dts-critic 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.22.2 || ^24.15.0 || >=26。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@definitelytyped/dts-critic 可以商用吗?

@definitelytyped/dts-critic 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@definitelytyped/dts-critic 的下载量有多少?

根据 npm 官方下载统计,@definitelytyped/dts-critic 在 2026/10/12 – 2026/11/10 这 30 天内被下载 36,370 次,日均约 1,212 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@definitelytyped/dts-critic 还在维护吗?

最新版本 0.1.38 发布于 2026/11/12(今天);至今共发布 171 个版本,其中过去 12 个月发布了 14 个;首次发布于 2021/12/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。