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:
-
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. -
code: in addition to the checks performed inname-onlymode, 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:
- An npm package with the same name of your declaration's package must exist.
- If your package has a Definitely Typed-conforming package.json, the npm package's version must match your version.
- If you are running under
codemode, 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):
- An npm package with the same name of your declaration's package cannot exist.
- If you are running under
codemode and a path to the JavaScript source file was provided, your declaration must also match the source JavaScript module.
Planned work
- Make sure your module structure fits the source.
- Make sure your exported symbols match the source.
- Make sure your types match the source types???
- 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.