From harness-claude
Constructs precise TypeScript string types using template literals and manipulation utilities like Capitalize, Uppercase, Lowercase. Applies to type-safe events, API routes, CSS values, getters/setters, and dot paths.
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeThis skill uses the workspace's default tool permissions.
> Construct precise string types using template literal syntax and string manipulation types
Explains and applies TypeScript utility types (Partial, Required, Pick, Omit, Readonly, Record) plus mapped and conditional types for flexible, type-safe code.
Masters TypeScript advanced types including generics, conditional types, mapped types, template literals, and utility types for type-safe applications. Use for complex type logic, reusable utilities, and compile-time safety in TS projects.
Guides TypeScript advanced types like generics, conditional types, mapped types, template literals, and utilities for type-safe libraries, APIs, and components. Use for complex type logic and inference.
Share bugs, ideas, or general feedback.
Construct precise string types using template literal syntax and string manipulation types
type EventName = `on${Capitalize<'click' | 'hover' | 'focus'>}`;
// 'onClick' | 'onHover' | 'onFocus'
type Color = 'red' | 'blue' | 'green';
type Size = 'sm' | 'md' | 'lg';
type ClassName = `${Color}-${Size}`;
// 'red-sm' | 'red-md' | 'red-lg' | 'blue-sm' | 'blue-md' | ...
type Events = {
click: { x: number; y: number };
change: { value: string };
submit: { data: FormData };
};
type OnEvent = `on${Capitalize<keyof Events>}`;
// 'onClick' | 'onChange' | 'onSubmit'
type Upper = Uppercase<'hello'>; // 'HELLO'
type Lower = Lowercase<'HELLO'>; // 'hello'
type Cap = Capitalize<'hello'>; // 'Hello'
type Uncap = Uncapitalize<'Hello'>; // 'hello'
type Getters<T> = {
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K];
};
type Setters<T> = {
[K in keyof T as `set${Capitalize<string & K>}`]: (value: T[K]) => void;
};
type UserAccessors = Getters<{ name: string; age: number }>;
// { getName: () => string; getAge: () => number }
infer:type ExtractRouteParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}`
? Param | ExtractRouteParams<`/${Rest}`>
: T extends `${string}:${infer Param}`
? Param
: never;
type Params = ExtractRouteParams<'/users/:userId/posts/:postId'>;
// 'userId' | 'postId'
type CSSUnit = 'px' | 'em' | 'rem' | '%' | 'vh' | 'vw';
type CSSLength = `${number}${CSSUnit}`;
function setWidth(width: CSSLength): void {
/* ... */
}
setWidth('100px'); // OK
setWidth('2.5rem'); // OK
setWidth('100'); // Error: not assignable to CSSLength
type DotPath<T, Prefix extends string = ''> = {
[K in keyof T & string]: T[K] extends object ? DotPath<T[K], `${Prefix}${K}.`> : `${Prefix}${K}`;
}[keyof T & string];
type Paths = DotPath<{ user: { name: string; address: { city: string } } }>;
// 'user.name' | 'user.address.city'
Template literal types (TypeScript 4.1+) allow string types to be composed from other string literals, unions, and type-level transformations. They are the string equivalent of mapped types — they generate new types by iterating over string combinations.
Distribution: When a template literal contains union types, it produces the Cartesian product. \${A | B}-${C | D}`produces'A-C' | 'A-D' | 'B-C' | 'B-D'`.
Intrinsic string manipulation types: Uppercase<S>, Lowercase<S>, Capitalize<S>, Uncapitalize<S> are built-in compiler intrinsics — they work on any string literal type.
Pattern matching: Template literal types with infer can extract parts of string types. This enables parsing route parameters, CSS values, and other structured strings at the type level.
Performance considerations:
\${100 values}-${100 values}`` creates 10,000 typesTrade-offs:
https://typescriptlang.org/docs/handbook/2/template-literal-types.html