Skip to content
Back to skills

Type Alias Compression

ASecurity

Extract repeated complex type expressions into named aliases that keep signatures readable.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 22, 2026
ai-agentsjavascripttypescriptpythonrustgojavanodeexpressrefactoringapi

Works with

  • cursor
  • api

Security analysis

A100/100

Scanned October 22, 2026

npx -y skills add alivirgo/Major-AI-Skills --skill type-alias-compression --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Type Alias Compression?

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

Security grade badge for Type Alias Compression
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/alivirgo-type-alias-compression/badge)](https://www.skillsdirectory.com/skills/alivirgo-type-alias-compression)

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-alias-compression
description: "Extract repeated complex type expressions into named aliases that keep signatures readable."
category: efficiency
risk: safe
source: self
source_type: self
date_added: "2026-08-26"
tags: ["type-aliases", "typescript-types", "generic-compression", "python-typing", "token-optimization", "clean-code"]
tools: ["claude", "cursor", "gemini", "codex", "lmstudio"]
---

# Type Alias Compression Protocol (Generic Signature Normalization)

## Overview
When writing enterprise applications in TypeScript, Python, or Rust, complex nested generic signatures (*e.g., `Promise<AxiosResponse<PaginatedResponse<UserProfileDTO>>>`*) are frequently repeated across 10 to 20 method definitions in a single module.

Repeating nested generic signatures causes:
1. **Severe Token Multiplication**: Repeating an 80-character generic signature across 15 functions burns **400+ output tokens** on syntax boilerplate.
2. **Maintenance Drift**: Changing the underlying response envelope requires mutating 15 separate function signatures across the file.
3. **Cognitive Clutter**: The actual function argument names are pushed off-screen by long type annotations.

The **Type Alias Compression Protocol** extracts common nested generic patterns into **concise top-level type aliases (`type Res<T> = ...`)**, normalizing signatures to **1 to 2 clean tokens**.

---

## Repetitive Nested Generics vs. Compressed Type Aliases

```
┌─────────────────────────────────────────────────────────────┐
│                 Type Signature Token Density                │
│                                                             │
│  Repetitive Nested Generics (15 Methods / 420 Tokens):      │
│  export async function getUser(id: string):                 │
│    Promise<AxiosResponse<ApiResponse<PaginatedResult<User>>>>{...}│
│  export async function getOrg(id: string):                  │
│    Promise<AxiosResponse<ApiResponse<PaginatedResult<Org>>>>{...} │
│  ↳ 420 tokens billed purely repeating identical generic wraps│
│                                                             │
│  Compressed Type Alias (1 Definition / 65 Tokens):          │
│  type ApiPage<T> = Promise<AxiosResponse<ApiResponse<PaginatedResult<T>>>>;│
│  export async function getUser(id: string): ApiPage<User> {...}│
│  export async function getOrg(id: string): ApiPage<Org> {...} │
│  ↳ 65 clean tokens (84.5% Reduction!), single point of change│
└─────────────────────────────────────────────────────────────┘
```

---

## Multi-Language Type Alias Compression Recipes

### 1. TypeScript / JavaScript
```typescript
// 1. Define High-Frequency Aliases at Top of File
export type AsyncResult<T> = Promise<{ data: T; error: null } | { data: null; error: string }>;
export type Handler<TReq, TRes> = (req: Request<TReq>, res: Response<TRes>) => Promise<void>;
export type ID = string | number;

// 2. Ultra-Clean Method Signatures
export async function fetchUser(id: ID): AsyncResult<User> { ... }
export async function updateProfile(id: ID, payload: UserDto): AsyncResult<User> { ... }
```

---

### 2. Python 3.12+ (PEP 695 Type Aliases)
```python
from typing import Callable, Coroutine, Any

# Python 3.12 native type statement
type JsonResult[T] = Coroutine[Any, Any, dict[str, T]]
type MiddlewareFn = Callable[[Request, Callable], Response]

async def get_user_profile(user_id: str) -> JsonResult[UserProfile]:
    ...
```

---

### 3. Rust Type Aliasing
```rust
use std::result::Result as StdResult;

// Aliasing heavy error types across the crate
pub type Result<T> = StdResult<T, AppEngineError>;
pub type UserMap = std::collections::HashMap<String, UserProfile>;

pub fn get_user(id: &str) -> Result<UserProfile> { ... }
```

---

## Benchmark Comparison

Generating a standard 12-method REST API controller:

| Implementation Pattern | Total Signature Tokens | Refactoring Friction | AST Complexity |
| :--- | :--- | :--- | :--- |
| **Inline Nested Generic Signatures** | 980 tokens | 12 files to change | High ($>18$ nodes/sig)|
| **Compressed Type Alias Protocol** | **340 tokens** | **1 alias to change**| **Low (2 nodes/sig)** |

---

## Agent Operational Directive
> **MANDATORY**: When a nested generic type signature is used $\ge 2$ times in a file or module, agents must extract it into a top-level type alias (`type Result<T> = ...`). Never repeat multi-layered generic chains across function signatures.

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.