Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@definitelytyped/dtslint

microsoft288.5kMIT0.2.32TypeScript support: included

Runs tests on TypeScript definition files

readme

dtslint tests a TypeScript declaration file for style and correctness. It will install typescript and eslint for you, so this is the only tool you need to test a type definition.

Lint rules new to dtslint are documented in the docs directory.

Just looking for a type testing tool?

If you are just looking for a TypeScript type testing tool, use:

Setup

If you are working on DefinitelyTyped, read the DefinitelyTyped README.

If you are writing the library in TypeScript, don't use dtslint. Use --declaration to have type definitions generated for you.

If you are a library author, read below.

Add types for a library (not on DefinitelyTyped)

dts-gen may help, but is not required.

Create a types directory. (Name is arbitrary.) Add "types": "types" to your package.json. Read more on bundling types here.

types/index.d.ts

Only index.d.ts and package.json need to be published to NPM. The other files will be required by Definitely Typed for testing. Write your type definitions in index.d.ts. Refer to the handbook or dts-gen's templates for how to do this.

types/tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "lib": [
            "es6",
        ],
        "noImplicitAny": true,
        "noImplicitThis": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "types": [],
        "noEmit": true,
        "forceConsistentCasingInFileNames": true
    },
    "files": [
        "index.d.ts",
        "PACKAGE-NAME-tests.ts",
    ]
}

You may extend "lib" to, for example, ["es6", "dom"] if you need those typings. You may also have to add "target": "es6" if using certain language features.

types/package.json

{
    "private": true,
    "name": "@types/PACKAGE-NAME",
    "version": "1.2.9999",
    "projects": [
        "https://example.com/"
    ],
    "dependencies": {
        "@types/DEPENDENCY-1": "*",
        "@types/DEPENDENCY-2": "*"
    },
    "devDependencies": {
        "@types/PACKAGE-NAME": "workspace:."
    },
    "owners": [
        {
            "name": "My Self",
            "githubUsername": "ghost"
        }
    ]
}
  1. If the types are for a scoped package, you must name-mangle @scope/package to @types/scope__package.
  2. The major and minor versions should match some published version of the npm package. The patch version must be 9999; Definitely Typed will increment published patch versions starting at 0, and the patch version of the types will not match the patch version of the npm package.
  3. "projects" is a link to the source project.
  4. There might not be any dependencies if the types don't rely on anything but standard types.
  5. "devDependencies" must include a self-reference like "@types/PACKAGE-NAME": "workspace:.. Plus any dependencies used only by tests.
  6. Non-@types dependencies must be added to allowedPackageJsonDependencies.txt in the definitions-parser package. The PR must be approved by a Typescript team member.
  7. If you do not have a github user name, you can provide a "url" of your own instead.

Also:

For types that do not have a matching NPM package, add two properties:

  1. "nonNpm": true
  2. "nonNpmDescription", a human-readable name for the project that is being typed.

types/.eslintrc.json

An .eslintrc.json file is optional. You can skip it if you don't need to modify any lint rule settings. We recommend not adding an .eslintrc.json file.

{ "extends": "@definitelytyped/dtslint/dt.json" }

If present, this will override dtslint's default "all" config. You can specify new lint rules, or disable some. An example:

{
    "rules": {
        "@definitelytyped/no-unnecessary-generics": "off"
    }
}

Please don't do this without a good reason. Disabling lint rules makes a Definitely Typed PR less likely to be merged, and will definitely take longer to review.

types/test.ts

You can have any number of test files you want, with any names. See below on what to put in them.

Write tests

A test file should be a piece of sample code that tests using the library. Tests are type-checked, but not run. To assert that an expression is of a given type, use $ExpectType. To assert that an expression causes a compile error, use @ts-expect-error. (Assertions will be checked by the expect lint rule.)

import { f } from "my-lib"; // f is(n: number) => void

// $ExpectType void
f(1);

// Can also write the assertion on the same line (but not if it's a multiline function call).
f(2); // $ExpectType void

// @ts-expect-error
f("one");

Specify a TypeScript version

Normally packages will be tested according to DefinitelyType's support window. To restrict testing to new versions only, specify it in package.json:

"minimumTypeScriptVersion: 5.6"

This tests only 5.6 and above, although people can still depend on the package with lower versions of Typescript if they want.

Run tests

  • npm install --save-dev @definitelytyped/dtslint
  • Add to your package.json scripts: "dtslint": "dtslint types"
  • npm run dtslint

Options

  • --localTs

Use your locally installed version of TypeScript.

dtslint --localTs node_modules/typescript/lib types
  • --expectOnly

Disable all the lint rules except the one that checks for type correctness.

dtslint --expectOnly types

Contributing

Build

npm link . # Global 'dts-lint' should now refer to this.
npm run watch

Test

Use pnpm test to run all tests.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

FAQ

I'm getting an error about a missing typescript install.

Error: Cannot find module '/node_modules/dtslint/typescript-installs/3.1/node_modules/typescript`

Your dependencies may be out of date. @definitelytyped/typescript-versions is the package that contains the list of TypeScript versions to install.

Alternatively this error can be caused by concurrent dtslint invocations trampling each other's TypeScript installations, especially in the context of continuous integration, if dtslint is installed from scratch in each run. If for example you use Lerna, try running dtslint with lerna --concurrency 1 run ....

changelog

@definitelytyped/dtslint

0.2.32

Patch Changes

0.2.31

Patch Changes

  • f98e138: More aggressively drop Programs to prevent OOMs

0.2.30

Patch Changes

0.2.29

Patch Changes

0.2.28

Patch Changes

0.2.27

Patch Changes

0.2.26

Patch Changes

0.2.25

Patch Changes

  • 5f556cf: Update to typescript-eslint v8

0.2.24

Patch Changes

0.2.23

Patch Changes

0.2.22

Patch Changes

0.2.21

Patch Changes

0.2.20

Patch Changes

0.2.19

Patch Changes

  • 98f77bf: Allow the jsxImportSource compiler option.

0.2.18

Patch Changes

  • e32483b: Retry and ignore npm errors

0.2.17

Patch Changes

0.2.16

Patch Changes

0.2.15

Patch Changes

  • 465dbce: Error on versioned directories when parent npmignores are missing subdir
  • 5dae397: Switch expect to using settings for versionsToTest

0.2.14

Patch Changes

0.2.13

Patch Changes

0.2.12

Patch Changes

0.2.11

Patch Changes

  • b9ca741: remove aws-lambda from expected npm version failures
  • b2f229a: Update arethetypeswrong

0.2.10

Patch Changes

  • 7668808: Update @arethetypeswrong/cli

0.2.9

Patch Changes

  • 57bb3ea: Rework error collection
  • 57bb3ea: Error if tslint.json is present
  • a79806d: Update arethetypeswrong version

0.2.8

Patch Changes

  • aa26880: Don’t crash when implementation package fails to extract

0.2.7

Patch Changes

0.2.6

Patch Changes

  • 2f106cb: Add missing warning logging

0.2.5

Patch Changes

0.2.4

Patch Changes

  • d7c81c7: Re-allow packages without tests
  • d7c81c7: Allow ./index.d.ts (with ./ prefix)

0.2.3

Patch Changes

  • 811aa2f: Allow .tsx tests in tsconfig

0.2.2

Patch Changes

  • fc26705: Require 1 .d.ts, 1 .ts in tsconfigs

0.2.1

Patch Changes

0.2.0

Minor Changes

  • 2d7a5d3: Require Node 18+

Patch Changes

0.1.5

Patch Changes

0.1.4

Patch Changes

  • 0a7fc7aa: Fix OOM when developing locally

0.1.3

Patch Changes

  • bbc3c792: Skip only npm-naming in dependents

0.1.2

Patch Changes

  • 1a5fdc83: Remove test files from packages
  • 6ff1c7bf: Require index.d.ts

0.1.1

Patch Changes

0.1.0

Minor Changes

  • 02c11c32: Remove TSLint remnants

Patch Changes

0.0.204

Patch Changes

0.0.203

Patch Changes

0.0.202

Patch Changes

0.0.201

Patch Changes

  • 92b5cd51: Remove more tslint code to make dtslint work again

0.0.200

Patch Changes

  • 414ae487: Move npm-naming lint rule from tslint to eslint
  • ae742dde: Special-case a useful error for pnpm test without arguments

0.0.199

Patch Changes

  • 30730f22: Use a direct require when finding estree import

0.0.198

Patch Changes

  • 3d6c2ffd: Port expect rule from tslint to eslint

0.0.197

Patch Changes

0.0.196

Patch Changes

  • 59076828: Remove void-return, switch on no-invalid-void-type

0.0.195

Patch Changes

  • 6f685060: Port tslint builtins -> eslint

0.0.194

Patch Changes

0.0.193

Patch Changes

0.0.192

Patch Changes

0.0.191

Patch Changes

  • a18ce6b1: Remove use of module resolution and OTHER_FILES, instead include all dts files in packages

    Files in packages are no longer determined by import resolution stemming from index.d.ts and tests (along with those listed in OTHER_FILES.txt). Instead, all files matching the glob **/*.d.{ts,cts,mts,*.d.ts} are included in the package, excluding those inside of versioned subdirectories.

    While not used for automated package publishing, an .npmignore is now required in each package. This allows for one-off npm pack-ing of packages, such that external tooling can get a rough approximation of what will be published for analysis.

  • Updated dependencies [a18ce6b1]

0.0.190

Patch Changes

0.0.189

Patch Changes

0.0.188

Patch Changes

0.0.187

Patch Changes

0.0.186

Patch Changes

0.0.185

Patch Changes

0.0.184

Patch Changes

0.0.183

Patch Changes

0.0.182

Patch Changes

  • 7d60c4b6: Restore explicit disabling of no-redundant-jsdoc

0.0.181

Patch Changes

  • 38396dff: Remove no-redundant-jsdoc2 rule

0.0.180

Patch Changes

  • c1d8ff25: Port no-single-declare-module tslint->eslint

0.0.179

Patch Changes

  • 08cc565f: Port strict-export-declare-modifiers tslint->eslint