{"name":"tsd","version":"0.32.0","keywords":["typescript","tsd","check","typings","types","typedefs","typedefinitions"],"author":{"url":"https://github.com/SamVerschueren","name":"Sam Verschueren","email":"sam.verschueren@gmail.com"},"license":"MIT","_id":"tsd@0.32.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"},{"name":"samverschueren","email":"sam.verschueren@gmail.com"}],"homepage":"https://github.com/tsdjs/tsd#readme","bugs":{"url":"https://github.com/tsdjs/tsd/issues"},"ava":{"files":["source/test/**/*","!source/test/fixtures/**/*"],"timeout":"2m","typescript":{"rewritePaths":{"source/":"dist/"}}},"bin":{"tsd":"dist/cli.js"},"dist":{"shasum":"3e15b0f2ecf880cafe4de1cfaa52980cf767d743","tarball":"http://registry-npm.ywwl.com/tsd/download/tsd-0.32.0.tgz","fileCount":53,"integrity":"sha512-R5lBZCbxGBowOcW0gpQaiIjGYrG5NmU+PfFDKcc3zbtzWjML1o/zAwzdDnS2ZheSlPu9GW51azpFqEPUBq9DoQ==","signatures":[{"sig":"MEUCIEwE5PjrpVg2odbGzSw+tmfK83Hw/ldsnG11MpLf1pyKAiEA6hZajglk8Rb17PSlPLNXjot8I86KGFRjDg3XDlbO/lk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":94905,"size":23187,"noattachment":false,"key":"/tsd/-/tsd-0.32.0.tgz"},"types":"./dist/index.d.ts","engines":{"node":">=14.16"},"exports":"./dist/index.js","gitHead":"f589fb3df03cbf37785ab029eeb1ec6ec5080dfd","scripts":{"lint":"eslint \"source/**/*\"","test":"npm run lint && ava","build":"npm run clean && tsc --project tsconfig.tsd.json && chmod +x dist/cli.js","clean":"del-cli dist","pretest":"npm run build && cpy \"./**/**\" \"../../../dist/test/fixtures/\" --parents --cwd=source/test/fixtures","lint:fix":"eslint --fix \"source/**/*\"","prepublishOnly":"npm run build"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/tsdjs/tsd.git","type":"git"},"_npmVersion":"10.9.2","description":"Check TypeScript type definitions","directories":{},"_nodeVersion":"23.6.1","dependencies":{"meow":"^9.0.0","globby":"^11.0.1","jest-diff":"^29.0.3","path-exists":"^4.0.0","read-pkg-up":"^7.0.0","@tsd/typescript":"~5.8.3","eslint-formatter-pretty":"^4.1.0"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^3.8.2","rxjs":"^6.5.3","execa":"^5.0.0","react":"^16.9.0","eslint":"^7.27.0","cpy-cli":"^3.0.0","del-cli":"^3.0.0","typescript":"~4.9.5","@types/node":"^14.18.21","@types/react":"^16.9.2","resolve-from":"^5.0.0","@ava/typescript":"^1.1.1","eslint-config-xo":"^0.36.0","@typescript-eslint/parser":"^4.26.0","eslint-config-xo-typescript":"^0.41.1","@typescript-eslint/eslint-plugin":"^4.26.0"},"_npmOperationalInternal":{"tmp":"tmp/tsd_0.32.0_1744204777373_0.017646397949010684","host":"s3://npm-registry-packages-npm-production"},"readme":"# tsd ![CI](https://github.com/tsdjs/tsd/workflows/CI/badge.svg)\n\n> Check TypeScript type definitions\n\n## Install\n\n```sh\nnpm install --save-dev tsd\n```\n\n## Overview\n\nThis tool lets you write tests for your type definitions (i.e. your `.d.ts` files) by creating files with the `.test-d.ts` extension.\n\nThese `.test-d.ts` files will not be executed, and not even compiled in the standard way. Instead, these files will be parsed for special constructs such as `expectError<Foo>(bar)` and then statically analyzed against your type definitions.\n\nThe `tsd` CLI will search for the main `.d.ts` file in the current or specified directory, and test it with any `.test-d.ts` files in either the same directory or a test sub-directory (default: `test-d`):\n\n```sh\n[npx] tsd [path]\n```\n\nUse `tsd --help` for usage information. See [Order of Operations](#order-of-operations) for more details on how `tsd` finds and executes tests.\n\n*Note: the CLI is primarily used to test an entire project, not a specific file. For more specific configuration and advanced usage, see [Configuration](#configuration) and [Programmatic API](#programmatic-api).*\n\n## Usage\n\nLet's assume we wrote a `index.d.ts` type definition for our concat module.\n\n```ts\ndeclare const concat: {\n\t(value1: string, value2: string): string;\n\t(value1: number, value2: number): string;\n};\n\nexport default concat;\n```\n\nIn order to test this definition, add a `index.test-d.ts` file.\n\n```ts\nimport concat from '.';\n\nconcat('foo', 'bar');\nconcat(1, 2);\n```\n\nRunning `npx tsd` as a command will verify that the type definition works correctly.\n\nLet's add some extra [assertions](#assertions). We can assert the return type of our function call to match a certain type.\n\n```ts\nimport {expectType} from 'tsd';\nimport concat from '.';\n\nexpectType<string>(concat('foo', 'bar'));\nexpectType<string>(concat(1, 2));\n```\n\nThe `tsd` command will succeed again.\n\nWe change our implementation and type definition to return a `number` when both inputs are of type `number`.\n\n```ts\ndeclare const concat: {\n\t(value1: string, value2: string): string;\n\t(value1: number, value2: number): number;\n};\n\nexport default concat;\n```\n\nIf we don't change the test file and we run the `tsd` command again, the test will fail.\n\n<img src=\"media/screenshot.png\" width=\"1330\">\n\n### Strict type assertions\n\nType assertions are strict. This means that if you expect the type to be `string | number` but the argument is of type `string`, the tests will fail.\n\n```ts\nimport {expectType} from 'tsd';\nimport concat from '.';\n\nexpectType<string>(concat('foo', 'bar'));\nexpectType<string | number>(concat('foo', 'bar'));\n```\n\nIf we run `tsd`, we will notice that it reports an error because the `concat` method returns the type `string` and not `string | number`.\n\n<img src=\"media/strict-assert.png\" width=\"1330\">\n\nIf you still want loose type assertion, you can use `expectAssignable` for that.\n\n```ts\nimport {expectType, expectAssignable} from 'tsd';\nimport concat from '.';\n\nexpectType<string>(concat('foo', 'bar'));\nexpectAssignable<string | number>(concat('foo', 'bar'));\n```\n\n### Top-level `await`\n\nIf your method returns a `Promise`, you can use top-level `await` to resolve the value instead of wrapping it in an `async` [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE).\n\n```ts\nimport {expectType, expectError} from 'tsd';\nimport concat from '.';\n\nexpectType<Promise<string>>(concat('foo', 'bar'));\n\nexpectType<string>(await concat('foo', 'bar'));\n\nexpectError(await concat(true, false));\n```\n\n## Order of Operations\n\nWhen searching for `.test-d.ts` files and executing them, `tsd` does the following:\n\n1. Locates the project's `package.json`, which needs to be in the current or specified directory (e.g. `/path/to/project` or `process.cwd()`). Fails if none is found.\n\n2. Finds a `.d.ts` file, checking to see if one was specified manually or in the `types` field of the `package.json`. If neither is found, attempts to find one in the project directory named the same as the `main` field of the `package.json` or `index.d.ts`. Fails if no `.d.ts` file is found.\n\n3. Finds `.test-d.ts` and `.test-d.tsx` files, which can either be in the project's root directory, a [specific folder](#test-directory) (by default `/[project-root]/test-d`), or specified individually [programatically](#testfiles) or via [the CLI](#via-the-cli). Fails if no test files are found.\n\n4. Runs the `.test-d.ts` files through the TypeScript compiler and statically analyzes them for errors.\n\n5. Checks the errors against [assertions](#assertions) and reports any mismatches.\n\n## Assertions\n\n### expectType&lt;T&gt;(expression: T)\n\nAsserts that the type of `expression` is identical to type `T`.\n\n### expectNotType&lt;T&gt;(expression: any)\n\nAsserts that the type of `expression` is not identical to type `T`.\n\n### expectAssignable&lt;T&gt;(expression: T)\n\nAsserts that the type of `expression` is assignable to type `T`.\n\n### expectNotAssignable&lt;T&gt;(expression: any)\n\nAsserts that the type of `expression` is not assignable to type `T`.\n\n### expectError&lt;T = any&gt;(expression: T)\n\nAsserts that `expression` throws an error. Will not ignore syntax errors.\n\n### expectDeprecated(expression: any)\n\nAsserts that `expression` is marked as [`@deprecated`](https://jsdoc.app/tags-deprecated.html).\n\n### expectNotDeprecated(expression: any)\n\nAsserts that `expression` is not marked as [`@deprecated`](https://jsdoc.app/tags-deprecated.html).\n\n### printType(expression: any)\n\nPrints the type of `expression` as a warning.\n\nUseful if you don't know the exact type of the expression passed to `printType()` or the type is too complex to write out by hand.\n\n### expectNever(expression: never)\n\nAsserts that the type and return type of `expression` is `never`.\n\nUseful for checking that all branches are covered.\n\n### expectDocCommentIncludes&lt;T&gt;(expression: any)\n\nAsserts that the documentation comment of `expression` includes string literal type `T`.\n\n## Configuration\n\n`tsd` is designed to be used with as little configuration as possible. However, if you need a bit more control, a project's `package.json` and the `tsd` CLI offer a limited set of configurations.\n\nFor more advanced use cases (such as integrating `tsd` with testing frameworks), see [Programmatic API](#programmatic-api).\n\n### Via `package.json`\n\n`tsd` uses a project's `package.json` to find types and test files as well as for some configuration. It must exist in the path given to `tsd`.\n\nFor more information on how `tsd` finds a `package.json`, see [Order of Operations](#order-of-operations).\n\n#### Test Directory\n\nWhen you have spread your tests over multiple files, you can store all those files in a test directory called `test-d`. If you want to use another directory name, you can change it in your project's `package.json`:\n\n```json\n{\n\t\"name\": \"my-module\",\n\t\"tsd\": {\n\t\t\"directory\": \"my-test-dir\"\n\t}\n}\n```\n\nNow you can put all your test files in the `my-test-dir` directory.\n\n#### Custom TypeScript Config\n\nBy default, `tsd` applies the following configuration:\n\n```json5\n{\n\t\"strict\": true,\n\t\"jsx\": \"react\",\n\t\"target\": \"es2020\",\n\t\"lib\": [\n\t\t\"es2020\",\n\t\t\"dom\",\n\t\t\"dom.iterable\"\n\t],\n\t\"module\": \"commonjs\",\n\t\"esModuleInterop\": true,\n\t\"noUnusedLocals\": false,\n\t// The following options are set and are not overridable.\n\t// Set to `nodenext` if `module` is `nodenext`, `node16` if `module` is `node16` or `node` otherwise.\n\t\"moduleResolution\": \"node\" | \"node16\" | \"nodenext\",\n\t\"skipLibCheck\": false\n}\n```\n\nThese options will be overridden if a `tsconfig.json` file is found in your project. You also have the possibility to provide a custom config by specifying it in `package.json`:\n\n```json\n{\n\t\"name\": \"my-module\",\n\t\"tsd\": {\n\t\t\"compilerOptions\": {\n\t\t\t\"strict\": false\n\t\t}\n\t}\n}\n```\n\n*Default options will apply if you don't override them explicitly. You can't override the `moduleResolution` or `skipLibCheck` options.*\n\n### Via the CLI\n\nThe `tsd` CLI is designed to test a whole project at once, and as such only offers a couple of flags for configuration.\n\n#### --typings\n\nAlias: `-t`\n\nPath to the type definition file you want to test. Same as [`typingsFile`](#typingsfile).\n\n#### --files\n\nAlias: `-f`\n\nAn array of test files with their path. Same as [`testFiles`](#testfiles).\n\n## Programmatic API\n\nYou can use the programmatic API to retrieve the diagnostics and do something with them. This can be useful to run the tests with AVA, Jest or any other testing framework.\n\n```ts\nimport tsd from 'tsd';\n\nconst diagnostics = await tsd();\n\nconsole.log(diagnostics.length);\n//=> 2\n```\n\nYou can also make use of the CLI's formatter to generate the same formatting output when running `tsd` programmatically.\n\n```ts\nimport tsd, {formatter} from 'tsd';\n\nconst formattedDiagnostics = formatter(await tsd());\n```\n\n### tsd(options?)\n\nRetrieve the type definition diagnostics of the project.\n\n#### options\n\nType: `object`\n\n##### cwd\n\nType: `string`\\\nDefault: `process.cwd()`\n\nCurrent working directory of the project to retrieve the diagnostics for.\n\n##### typingsFile\n\nType: `string`\\\nDefault: The `types` property in `package.json`.\n\nPath to the type definition file you want to test. This can be useful when using a test runner to test specific type definitions per test.\n\n##### testFiles\n\nType: `string[]`\\\nDefault: Finds files with `.test-d.ts` or `.test-d.tsx` extension.\n\nAn array of test files with their path. Uses [globby](https://github.com/sindresorhus/globby) under the hood so that you can fine tune test file discovery.\n","publish_time":1744204777563,"_cnpm_publish_time":1744204777563,"dist-tags":{"beta":"0.6.5-beta","beta.2":"0.6.5-beta.2","latest":"0.33.0","next":"0.6.0-beta.5"}}