{"id":16347940,"url":"https://github.com/ai/check-dts","last_synced_at":"2025-04-04T08:10:01.913Z","repository":{"id":48329470,"uuid":"239052722","full_name":"ai/check-dts","owner":"ai","description":"Unit tests for TypeScript definitions in your JS open source library","archived":false,"fork":false,"pushed_at":"2024-08-20T23:25:15.000Z","size":998,"stargazers_count":141,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-11-24T17:54:33.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/ai.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"ai"}},"created_at":"2020-02-08T01:40:07.000Z","updated_at":"2024-10-23T11:27:15.000Z","dependencies_parsed_at":"2024-05-21T21:48:29.663Z","dependency_job_id":"554d9e6f-3143-4b96-abbc-686f382767d1","html_url":"https://github.com/ai/check-dts","commit_stats":{"total_commits":169,"total_committers":15,"mean_commits":"11.266666666666667","dds":0.1301775147928994,"last_synced_commit":"61d211dff1e96a692d7be9611d72b2e92526be65"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai%2Fcheck-dts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai%2Fcheck-dts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai%2Fcheck-dts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ai%2Fcheck-dts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ai","download_url":"https://codeload.github.com/ai/check-dts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142074,"owners_count":20890653,"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-10-11T00:47:23.593Z","updated_at":"2025-04-04T08:10:01.885Z","avatar_url":"https://github.com/ai.png","language":"JavaScript","funding_links":["https://github.com/sponsors/ai"],"categories":[],"sub_categories":[],"readme":"# Check TypeScript Definitions\n\nUnit tests for `.d.ts` TypeScript definitions in your JavaScript\nopen source library.\n\nIt is useful for non-TypeScript project, which wants to provide typing\nsupport for TypeScript users and autocompletion for IDE and text editors.\n\nIt becomes especially useful for complex types with generics, like we have\nin [Nano Events] or [Storeon].\n\n```ts\n// Negative test: test/index.errors.ts\nimport lib = require('../')\n\ninterface Events {\n  'set': (a: string, b: number) =\u003e void\n}\n// THROWS Expected 3 arguments, but got 2\nlib.on\u003cEvents\u003e('set', 2)\n```\n\n```ts\n// Positive test: test/index.types.ts\nimport lib = require('../')\n\ninterface Events {\n  'set': (a: string, b: number) =\u003e void\n}\nlib.on\u003cEvents\u003e('set', 'prop', 1)\n```\n\n[Nano Events]: https://github.com/ai/nanoevents/#typescript\n[Storeon]: https://github.com/storeon/storeon#typescript\n\n\u003cimg src=\"./screenshot.png\" alt=\"Print Snapshots example\" width=\"585\"\u003e\n\n\u003ca href=\"https://evilmartians.com/?utm_source=check-dts\"\u003e\n  \u003cimg src=\"https://evilmartians.com/badges/sponsored-by-evil-martians.svg\"\n      alt=\"Sponsored by Evil Martians\" width=\"236\" height=\"54\"\u003e\n\u003c/a\u003e\n\n## Usage\n\n1. Add `.d.ts` files with TypeScript definitions for your JS library.\n   You can check example in\n   [Nano Events](https://github.com/ai/nanoevents/blob/main/index.d.ts).\n2. Install `check-dts`:\n\n   ```sh\n   npm install --save-dev check-dts\n   ```\n\n3. Create `test/index.types.ts` for positive tests and write correct TypeScript.\n   You can test IDE autocompletion in this file.\n4. Run `npx check-dts` to test the new file.\n5. Create `test/index.errors.ts` for negative tests and add an incorrect usage\n   of your library recording to TypeScript. See the next section for details.\n6. Run `npx check-dts` to test both files.\n7. Add `check-dts` to `npm test` to test types on CI:\n\n   ```diff\n     \"scripts\": {\n   -   \"test\": \"jest \u0026\u0026 eslint .\"\n   +   \"test\": \"jest \u0026\u0026 eslint . \u0026\u0026 check-dts\"\n     }\n   ```\n\n8. If your library requires an additional TypeScript option, you can define it\n   for tests in `tsconfig.json`.\n\n\n## Writing Negative Test\n\nAdd code where you expect TypeScript to report an error. Make sure to add a\nline above the expected error like `// THROWS some error messages`\n\n```ts\nimport lib = require('../')\n\ninterface Events {\n  set: (a: string, b: number) =\u003e void\n}\nlib.on\u003cEvents\u003e('set', 2)\n```\n\nIn this case, we expect the error message `Expected 3 arguments, but got 2`.\nSo we should add comments. You can put only part of the error message\nto the `// THROWS comment`.\n\n```diff\n  import lib = require('../')\n\n  interface Events {\n    set: (a: string, b: number) =\u003e void\n  }\n+ // THROWS Expected 3 arguments, but got 2\n  lib.on\u003cEvents\u003e('set', 2)\n```\n\nIf TypeScript does not report the error or reports a different error,\n`check-dts` will fall with a description:\n\n```bash\n$ npx check-dts\n✖ Check types\n\n✖ test/index.errors.ts:7:23: Wrong error\n  Expected: Expected 0 arguments, but got 1\n  Got: Expected 3 arguments, but got 2.\n```\n\n\n## CLI Options\n\nTest all `.ts` and `.js` files in project and run `*.types.ts` and `*.errors.ts`\ntests:\n\n```bashsh\nnpx check-dts\n```\n\nYou can test only specific files by:\n\n```sh\nnpx check-dts **/*.tsx?\nnpx check-dts **/*.ts !**/index.ts\n```\n\n\n## FAQ\n\n### It seems that check-dts ignores all d.ts-files. How can I fix this?\n\nPlease make sure that your tsconfig.json doesn’t include `skipLibCheck: true`.\nBecuase with this [option](https://www.typescriptlang.org/tsconfig#skipLibCheck)\nall `d.ts`-files will be ignored.\n\n\n### Can I use check-dts as a simple validator for d.ts-files?\n\nYes you can. But note if you have the typescript in your project\nyou can validate whether `d.ts`-files have some issues with the following command:\n\n```sh\nnpx tsc path/to/your/dts/files/**/*.d.ts --noEmit\n```\n\n\n### I am getting an error **from Node types**, how do I skip `node_modules`?\n\nIf you are getting an error that looks something like this:\n\n```\n✖ node_modules/@types/node/globals.d.ts:68:13: Type error TS2502\n  'AbortController' is referenced directly or indirectly in its own type annotation.\n```\n\nYou can skip the whole `node_modules` by adding to `tsconfig.json`:\n\n\n```json\n{\n  \"compilerOptions\": {\n    \"skipLibCheck\": true\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai%2Fcheck-dts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fai%2Fcheck-dts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fai%2Fcheck-dts/lists"}