tsd is a utility designed for testing TypeScript type definitions, enabling developers to verify the correctness of their `.d.ts` files. The current stable version is 0.33.0, and the project maintains a relatively frequent release cadence, often updating to support newer TypeScript versions shortly after their release. It distinguishes itself by performing static analysis on `.test-d.ts` files, interpreting special assertion functions like `expectType`, `expectError`, and `expectAssignable` to check type compatibility without executing runtime code. This approach ensures that your type definitions accurately reflect your module's API and behavior, catching potential type-related regressions before they manifest as runtime errors or incorrect IDE IntelliSense. tsd is primarily used via its CLI, which automatically discovers project `package.json`, main type definition files, and test files within a configured directory.
npm install tsdVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a type, write basic `tsd` tests using `expectType`, `expectAssignable`, and `expectError` assertions, and how to test asynchronous operations.
If a looser check is intended, use `expectAssignable<ExpectedType>(ActualValue)` instead of `expectType`.
Always ensure your project's TypeScript version is compatible with the `tsd` version you are using. Consult `tsd`'s release notes for the specific TypeScript version it depends on, and upgrade your project's TypeScript if necessary.
For comprehensive type testing, structure your project with a `package.json` and follow the `tsd` convention for `.test-d.ts` files. For very specific, isolated type checks, consider using the programmatic API or a simpler TypeScript compiler API script.
This error occurs because `expectType` requires an exact type match. If `string` is the actual and intended type, change `expectType<string | number>` to `expectType<string>`. If you want to check for assignability (a looser check), use `expectAssignable<string | number>('foo')`.Ensure you are running `tsd` from the root directory of your project, or explicitly pass the path to your project's root directory: `npx tsd /path/to/your/project`.
Specify the path to your main declaration file in your `package.json` using the `types` field (e.g., `"types": "dist/index.d.ts"`), or ensure `index.d.ts` is in your project root or the specified path.
No dependency data recorded yet.