Comprehensive TypeScript guidance covering compiler configuration, advanced types, utility types, type guards, strict mode workflows, and documentation patterns; use when configuring tsconfig, designing complex generics, making illegal states unrepresentable, fixing type errors, or writing testable and maintainable type-safe APIs.
Overall
score
99%
Does it follow best practices?
Validation for skill structure
Create distinct types from primitives to prevent mixing incompatible values.
type Brand<K, T> = K & { __brand: T };
type UserId = Brand<string, 'UserId'>;
type ProductId = Brand<string, 'ProductId'>;
// Factory functions
const createUserId = (id: string): UserId => id as UserId;
const createProductId = (id: string): ProductId => id as ProductId;
const userId = createUserId('user-123');
const productId = createProductId('prod-456');
// Type error: can't mix branded types
// getUser(productId); // Error!
function getUser(id: UserId) {
return { id, name: 'Alice' };
}type Email = Brand<string, 'Email'>;
type PhoneNumber = Brand<string, 'PhoneNumber'>;
const createEmail = (value: string): Email => {
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
throw new Error('Invalid email');
}
return value as Email;
};
const createPhoneNumber = (value: string): PhoneNumber => {
if (!/^\+?[\d\s-()]+$/.test(value)) {
throw new Error('Invalid phone number');
}
return value as PhoneNumber;
};
// Usage
const email = createEmail('user@example.com'); // OK
// const invalid = createEmail('not-an-email'); // Throwstype PositiveInt = Brand<number, 'PositiveInt'>;
type Percentage = Brand<number, 'Percentage'>;
const createPositiveInt = (n: number): PositiveInt => {
if (!Number.isInteger(n) || n <= 0) {
throw new Error('Must be a positive integer');
}
return n as PositiveInt;
};
const createPercentage = (n: number): Percentage => {
if (n < 0 || n > 100) {
throw new Error('Must be between 0 and 100');
}
return n as Percentage;
};import { z } from 'zod';
const UserIdSchema = z.string().uuid().brand('UserId');
type UserId = z.infer<typeof UserIdSchema>;
const EmailSchema = z.string().email().brand('Email');
type Email = z.infer<typeof EmailSchema>;
// Validation
const userId = UserIdSchema.parse('550e8400-e29b-41d4-a716-446655440000');
const email = EmailSchema.parse('user@example.com');Install with Tessl CLI
npx tessl i pantheon-ai/typescript-advancedreferences