Skip to content
Back to skills

Kitz Type Assertions

ASecurity

Type assertion patterns using @kitz/assert. Triggers on type-level tests, .test-d.ts files, or when asserting TypeScript types.

  • 666 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added February 9, 2026
developmenttypescriptapi

Works with

  • api

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill kitz-type-assertions --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Kitz Type Assertions?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Kitz Type Assertions
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-kitz-type-assertions/badge)](https://www.skillsdirectory.com/skills/majiayu000-kitz-type-assertions)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: type-assertions
description: Type assertion patterns using @kitz/assert. Triggers on type-level tests, .test-d.ts files, or when asserting TypeScript types.
---

# Type Assertions

## Import

```typescript
import { Assert } from '@kitz/assert'
```

## Builder Pattern

Assertions use a fluent builder: `Assert.<relator>.<matcher>(expected).<setting>().on(actual)`

### Relators (Required First)

| Relator  | Meaning                     |
| -------- | --------------------------- |
| `.exact` | Types must be identical     |
| `.equiv` | Bidirectional assignability |
| `.sub`   | Actual extends expected     |

### Unary Matchers (No Expected Type)

```typescript
Assert.exact.any.on(value) // value is any
Assert.exact.unknown.on(value) // value is unknown
Assert.exact.never.on(value) // value is never
Assert.exact.empty.on(value) // value is {}
```

### Binary Matchers

```typescript
// Value-level (preferred)
Assert.exact.of(expected).on(actual)

// Type-level only
Assert.exact.ofAs<Expected>().onAs<Actual>()

// Shorthand matchers
Assert.exact.string.on(value)
Assert.exact.number.on(value)
Assert.exact.boolean.on(value)
Assert.exact.bigint.on(value)
Assert.exact.symbol.on(value)
Assert.exact.null.on(value)
Assert.exact.undefined.on(value)
Assert.exact.void.on(value)
Assert.exact.object.on(value)
Assert.exact.function.on(value)
```

### Settings (Optional)

```typescript
// Negate assertion
Assert.exact.of(string).not.on(value) // value is NOT string

// Control type inference
Assert.exact.of(expected).inferNarrow().on(actual) // narrow inference
Assert.exact.of(expected).inferWide().on(actual) // wide inference
Assert.exact.of(expected).inferAuto().on(actual) // default
```

### Extractors

```typescript
// Extract return type
Assert.exact.string.returned.on(fn) // ReturnType<fn> is string

// Extract awaited type
Assert.exact.string.awaited.on(promise) // Awaited<promise> is string

// Extract parameters
Assert.exact.of([string, number]).parameters.on(fn)

// Extract array element
Assert.exact.string.array.on(arr) // arr is string[]
```

## Preferred Pattern

__ALWAYS prefer value-level API__ - it reports ALL failures simultaneously:

```typescript
// In .test.ts files
test('types', () => {
  const value = getValue()
  Assert.exact.string.on(value)
  Assert.exact.of({ a: 1 }).on(obj)
})

// In .test-d.ts files (pure type-level)
Assert.exact.ofAs<string>().onAs<string>()
Assert.exact.ofAs<number>().onAs<number>()

// @ts-expect-error - type mismatch
Assert.exact.ofAs<string>().onAs<number>()
```

## Avoid

```typescript
// DON'T use type-level only assertions in test blocks
test('bad', () => {
  type _ = Assert.exact.of<string, number> // Short-circuits on first error
})
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.