Agent skill
type-parameters
Type parameter naming conventions for personal TypeScript projects. Triggers on generic type/function creation, type-level code, or when asking about TypeScript generics.
Stars
163
Forks
31
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/ts-type-parameters
SKILL.md
Type Parameter Naming
Convention
-
Type aliases and interfaces: Use
$prefixtype Transform<$Input> = $Input extends string ? number : booleaninterface Container<$T> { value: $T }
-
Functions and methods: Use
$prefix matching the value parameter namefunction process<$value>(value: $value): $valuefunction map<$item, $result>(item: $item, fn: ($item) => $result): $result
-
Type guard exception: Add
_suffix to avoid conflict with narrowed typefunction isString<$value_>(value: unknown): value is $value_
-
Generic returns exception: When type param is NOT mapped to value parameter
function create<$T>(): $T
-
Utility internals: Parameters with
___prefix are implementation detailstype Utility<$T, ___Internal = SomeDefault<$T>> = ...
-
Mapped types: Use specific single-letter iterators
- Objects:
k(key) -{ [k in keyof $T]: $T[k] } - Tuples/arrays:
i(index) -{ [i in keyof $T]: Transform<$T[i]> }
- Objects:
-
Infer clauses: Use
__lowercase__pattern$T extends Array<infer __element__> ? __element__ : never
Type Parameter Defaults
Default type parameters to their widest possible variant:
typescript
// GOOD - Defaults to widest
type ParserContext<
$Schema = Schema | undefined,
$SDDM = any,
$TypeHooks = never
> = ...
// Usage with clean constraints
function parse<$Context extends ParserContext>(...) // Clean!
// BAD - Cluttered constraint
function parse<$Context extends ParserContext<any, any, any>>(...) // Ugly!
Didn't find tool you were looking for?