feat: Add Vitest integration for type-testing#11
Conversation
Add native Vitest integration for type-testing with custom matchers:
- toBeType, toNotBeType - type equality checks
- toExtend, toNotExtend - type extends checks
- toHaveProperty - property existence check
- toBeAny, toBeNever, toBeUnknown - special type checks
- toBeVoid, toBeUndefined, toBeNull - primitive type checks
- toBeNullable, toBeOptional - optional type checks
- toBeUnion, toBeTuple, toBeArray - structure checks
- toBeInhabited, toBeUninhabited - inhabitation checks
- expectType - helper function for type testing
Also adds:
- setup.ts for Vitest integration
- 36 new tests for the vitest module
Usage:
```typescript
import { expectType } from '@deessejs/type-testing/vitest'
expectType<string>().toBeType<string>()
expectType<{ a: string }>().toHaveProperty('a')
```
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Add 55 new runtime tests for vitest matchers to achieve 100% coverage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| /** | ||
| * Creates a Vitest matcher for type inequality. | ||
| */ | ||
| export function toNotBeType<T, U>(): NotEqual<T, U> extends true ? CheckPass : never { |
There was a problem hiding this comment.
This matcher follows a different naming convention than standard Jest/Vitest matchers which typically use toBe/not.toBe pattern. Consider adding toBeNotType as an alias or documenting this intentional deviation.
| toBeInhabited(): IsInhabited<T> extends true ? CheckPass : never | ||
| toBeUninhabited(): IsUninhabited<T> extends true ? CheckPass : never | ||
| } { | ||
| return {} as any |
There was a problem hiding this comment.
Good use of the type holder pattern. The return type casting with {} as any is necessary but consider adding a comment explaining why this is needed for the type testing pattern.
SummaryThis PR adds a native Vitest integration for the type-testing library, providing 18 custom type matchers and an Critical IssuesNone identified. The implementation is solid and follows best practices. Recommendations
Positive Notes
TestingThe test file ( Verdict: Approve with minor documentation recommendations. |
Add comprehensive documentation for the new Vitest integration feature: - Quick start guide - Usage with expect.extend - Setup file configuration - Complete matcher reference table - Note about toNotBeType naming convention Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| * ``` | ||
| */ | ||
|
|
||
| export { expectType } from './matchers.js' |
There was a problem hiding this comment.
The setup file exports expectType but doesn't actually extend Vitest's expect with the matchers. The README suggests using this as a setup file (line 414), but it only re-exports expectType without calling expect.extend(). This means users need to manually call expect.extend({ toBeType, ... }) or import the matchers directly.
If the setup file is meant to auto-register matchers, it should include:
import { expect } from 'vitest'
import * as matchers from './matchers.js'
expect.extend(matchers)Otherwise, consider clarifying in the documentation that this only exports expectType for convenience.
SummaryThe PR adds a comprehensive Vitest integration for the type-testing library, providing 18 custom type matchers and an Critical Issues1. Setup file doesn't register matchers automatically The setup file (
Recommendations2. Consider adding TypeScript declarations for Vitest matchers The current implementation uses runtime 3. Tests could include negative test cases The current tests verify type signatures work correctly but don't test that type errors are properly triggered for failing cases. Consider adding tests that verify incorrect type assertions produce compile-time errors. Positive Notes
Overall, this is a solid implementation with a minor issue around the setup file's functionality. |
Simplify matcher functions to achieve full coverage. These functions return undefined at runtime while type checking happens at compile time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
expectType<T>()syntax for Vitest usersUsage Example
Or with Vitest's expect.extend:
Test Plan
🤖 Generated with Claude Code