{"id":13527025,"url":"https://github.com/Microsoft/dtslint","last_synced_at":"2025-04-01T09:30:58.467Z","repository":{"id":17893946,"uuid":"82734331","full_name":"microsoft/dtslint","owner":"microsoft","description":"A utility built on TSLint for linting TypeScript declaration (.d.ts) files.","archived":true,"fork":false,"pushed_at":"2022-04-07T21:41:35.000Z","size":1341,"stargazers_count":926,"open_issues_count":92,"forks_count":86,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-03-30T21:38:03.070Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2017-02-21T22:38:37.000Z","updated_at":"2025-03-27T16:10:43.000Z","dependencies_parsed_at":"2022-08-07T09:00:22.287Z","dependency_job_id":null,"html_url":"https://github.com/microsoft/dtslint","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fdtslint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fdtslint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fdtslint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoft%2Fdtslint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoft","download_url":"https://codeload.github.com/microsoft/dtslint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246385406,"owners_count":20768668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T06:01:39.505Z","updated_at":"2025-04-01T09:30:57.707Z","avatar_url":"https://github.com/microsoft.png","language":"TypeScript","readme":"This repo has moved: dtslint is now part of DefinitelyTyped-tools.\r\n\r\nIt is not intended to be used on its own, but as part of the `@definitelytyped` set of packages.\r\nThe source code has moved to https://github.com/microsoft/DefinitelyTyped-tools\r\nThe new package name is `@definitelytyped/dtslint`.\r\n\r\n`dtslint` tests a TypeScript declaration file for style and correctness.\r\nIt will install `typescript` and `tslint` for you, so this is the only tool you need to test a type definition.\r\n\r\nLint rules new to dtslint are documented in the [docs](docs) directory.\r\n\r\n# Just looking for ExpectType and ExpectError?\r\n\r\n[Use tsd instead](https://github.com/SamVerschueren/tsd).\r\n\r\n# Setup\r\n\r\nIf you are working on DefinitelyTyped, read the [DefinitelyTyped README](https://github.com/DefinitelyTyped/DefinitelyTyped#readme).\r\n\r\nIf you are writing the library in TypeScript, don't use `dtslint`.\r\nUse [`--declaration`](http://www.typescriptlang.org/docs/handbook/compiler-options.html) to have type definitions generated for you.\r\n\r\nIf you are a library author, read below.\r\n\r\n\r\n## Add types for a library (not on DefinitelyTyped)\r\n\r\n[`dts-gen`](https://github.com/Microsoft/dts-gen#readme) may help, but is not required.\r\n\r\nCreate a `types` directory. (Name is arbitrary.)\r\nAdd `\"types\": \"types\"` to your `package.json`.\r\nRead more on bundling types [here](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html).\r\n\r\n\r\n#### `types/index.d.ts`\r\n\r\nOnly `index.d.ts` needs to be published to NPM. Other files are just for testing.\r\nWrite your type definitions here.\r\nRefer to the [handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html) or `dts-gen`'s templates for how to do this.\r\n\r\n\r\n#### `types/tsconfig.json`\r\n\r\n```json5\r\n{\r\n    \"compilerOptions\": {\r\n        \"module\": \"commonjs\",\r\n        \"lib\": [\"es6\"],\r\n        \"noImplicitAny\": true,\r\n        \"noImplicitThis\": true,\r\n        \"strictFunctionTypes\": true,\r\n        \"strictNullChecks\": true,\r\n        \"types\": [],\r\n        \"noEmit\": true,\r\n        \"forceConsistentCasingInFileNames\": true,\r\n\r\n        // If the library is an external module (uses `export`), this allows your test file to import \"mylib\" instead of \"./index\".\r\n        // If the library is global (cannot be imported via `import` or `require`), leave this out.\r\n        \"baseUrl\": \".\",\r\n        \"paths\": { \"mylib\": [\".\"] }\r\n    }\r\n}\r\n```\r\n\r\nYou may extend `\"lib\"` to, for example, `[\"es6\", \"dom\"]` if you need those typings.\r\nYou may also have to add `\"target\": \"es6\"` if using certain language features.\r\n\r\n\r\n#### `types/tslint.json`\r\n\r\nIf you are using the default rules, this is optional.\r\n\r\nIf present, this will override `dtslint`'s [default](https://github.com/Microsoft/dtslint/blob/master/dtslint.json) settings.\r\nYou can specify new lint [rules](https://palantir.github.io/tslint/rules/), or disable some. An example:\r\n\r\n```json5\r\n{\r\n    \"extends\": \"dtslint/dtslint.json\", // Or \"dtslint/dt.json\" if on DefinitelyTyped\r\n    \"rules\": {\r\n        \"semicolon\": false,\r\n        \"indent\": [true, \"tabs\"]\r\n    }\r\n}\r\n```\r\n\r\n\r\n#### `types/test.ts`\r\n\r\nYou can have any number of test files you want, with any names. See below on what to put in them.\r\n\r\n\r\n\r\n## Write tests\r\n\r\nA test file should be a piece of sample code that tests using the library. Tests are type-checked, but not run.\r\nTo assert that an expression is of a given type, use `$ExpectType`.\r\nTo assert that an expression causes a compile error, use `$ExpectError`.\r\n(Assertions will be checked by the `expect` lint rule.)\r\n\r\n```ts\r\nimport { f } from \"my-lib\"; // f is(n: number) =\u003e void\r\n\r\n// $ExpectType void\r\nf(1);\r\n\r\n// Can also write the assertion on the same line.\r\nf(2); // $ExpectType void\r\n\r\n// $ExpectError\r\nf(\"one\");\r\n```\r\n\r\n\r\n## Specify a TypeScript version\r\n\r\nNormally packages will be tested using TypeScript 2.0.\r\nTo use a newer version, specify it by including a comment like so:\r\n\r\n```ts\r\n// Minimum TypeScript Version: 2.1\r\n```\r\n\r\nFor DefinitelyTyped packages, this should go just under the header (on line 5).\r\nFor bundled typings, this can go on any line (but should be near the top).\r\n\r\n\r\n## Run tests\r\n\r\n- `npm install --save-dev dtslint`\r\n- Add to your `package.json` `scripts`: `\"dtslint\": \"dtslint types\"`\r\n- `npm run dtslint`\r\n\r\n### Options\r\n\r\n- `--localTs`\r\n\r\nUse your locally installed version of TypeScript.\r\n\r\n```sh\r\ndtslint --localTs node_modules/typescript/lib types\r\n```\r\n- `--expectOnly`\r\n\r\nDisable all the lint rules except the one that checks for type correctness.\r\n\r\n```sh\r\ndtslint --expectOnly types\r\n```\r\n\r\n\r\n# Contributing\r\n\r\n## Build\r\n\r\n```sh\r\nnpm link . # Global 'dts-lint' should now refer to this.\r\nnpm run watch\r\n```\r\n\r\n## Test\r\n\r\nUse `npm run test` to run all tests.\r\nTo run a single test: `node node_modules/tslint/bin/tslint --rules-dir bin/rules --test test/expect`.\r\n\r\n## Publish\r\n\r\n1. Change the version in the `package.json`\r\n2. Push to master\r\n\r\n## Code of Conduct\r\n\r\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\r\n\r\n## FAQ\r\nI'm getting an error about a missing typescript install.\r\n```\r\nError: Cannot find module '/node_modules/dtslint/typescript-installs/3.1/node_modules/typescript`\r\n```\r\nYour dependencies may be out of date.\r\n[@definitelytyped/typescript-versions](https://github.com/microsoft/DefinitelyTyped-tools/tree/master/packages/typescript-versions) is the package that contains the list of TypeScript versions to install.\r\n\r\nAlternatively 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.\r\nIf for example you use [Lerna](https://github.com/lerna/lerna/tree/main/commands/run#readme), try running dtslint with [`lerna --concurrency 1 run ...`](https://github.com/lerna/lerna/tree/main/core/global-options#--concurrency).\r\n","funding_links":[],"categories":["Repository"],"sub_categories":["Linter \u0026 Formatter"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMicrosoft%2Fdtslint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMicrosoft%2Fdtslint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMicrosoft%2Fdtslint/lists"}