Integration
Setup
If you're a library author wanting to integrate type into your own assertions instead of using the attest API, you'll need to call setup with a list of attestAliases to ensure type data is collected from your own functions:
You'll need to make sure that setup with whatever aliases you need before the first test runs. As part of the setup process, attest will search for the specified assertion calls and cache their types in a temporary file that will be referenced during test execution.
This ensures that type assertions can be made across processes without creating a new TSServer instance for each.
TS Versions
Attest analyzes your project with whichever version of typescript is installed. To test multiple versions, run your suite once per version, e.g. via a CI matrix that installs each version before running tests.
TypeScript 7.1+ is supported via its native API. Type assertions, completions, JSDoc, benches and the CLI work the same way, with a few differences:
- Instantiation counts are measured by running
tsc --extendedDiagnostics --singleThreadedper bench. Sincetscfully checks the bench's dependencies before measuring it, work a bench shares with them isn't attributed to the bench, so counts run lower than with TypeScript 5/6, by as much as most of the count for a bench whose cost is mostly shared with its dependencies, and baselines should be recorded separately. - Type strings, union ordering and error elaboration can differ from earlier versions, so snapshots may need to be updated when switching.
- Benches write temporary copies beside their source files while measuring, so they need a writable source directory.
APIs
The most flexible attest APIs are getTypeAssertionAtPosition and caller.
Here's an example of how you might use them in your own API:
A user might then use yourCustomAssert like this:
Please don't hesitate to open a GitHub issue or discussion or reach out on ArkType's Discord if you have any questions or feedback- we'd love to hear from you! ⛵