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
Represent values that can be one of several types:
type Result = Success | Failure;
type ID = string | number;
type Status = 'pending' | 'approved' | 'rejected';
function handleResult(result: Result) {
// Type narrowing required to access specific properties
if ('data' in result) {
console.log(result.data);
}
}Combine multiple types into one:
type Named = { name: string };
type Aged = { age: number };
type Person = Named & Aged;
const person: Person = {
name: 'Alice',
age: 30
};
// Useful for mixins
type Timestamped = { createdAt: Date; updatedAt: Date };
type User = Person & Timestamped;Union types with a common discriminant property for type-safe narrowing:
type Success = {
kind: 'success';
data: string;
};
type Failure = {
kind: 'failure';
error: Error;
};
type Result = Success | Failure;
function handleResult(result: Result) {
switch (result.kind) {
case 'success':
console.log(result.data); // TypeScript knows this is Success
break;
case 'failure':
console.error(result.error); // TypeScript knows this is Failure
break;
}
}Model state machines type-safely:
type IdleState = { status: 'idle' };
type LoadingState = { status: 'loading'; startedAt: Date };
type SuccessState = { status: 'success'; data: string };
type ErrorState = { status: 'error'; error: Error };
type State = IdleState | LoadingState | SuccessState | ErrorState;
function transition(state: State): State {
switch (state.status) {
case 'idle':
return { status: 'loading', startedAt: new Date() };
case 'loading':
// Can access startedAt here
return Math.random() > 0.5
? { status: 'success', data: 'result' }
: { status: 'error', error: new Error('Failed') };
case 'success':
case 'error':
return { status: 'idle' };
}
}// Intersection - combines types
type A = { a: string };
type B = { b: number };
type C = A & B; // { a: string; b: number }
// Extension - interface inheritance
interface D extends A, B {
c: boolean;
}
// Intersection allows for more flexible composition
type Mixed = A & { c: boolean } & B;type Config = {
required: string;
} & (
| { mode: 'development' }
| { mode: 'production'; apiKey: string }
);type Brand<T, B> = T & { __brand: B };
type UserId = Brand<string, 'UserId'>;
type Email = Brand<string, 'Email'>;
// UserId and Email are incompatible despite both being stringsInstall with Tessl CLI
npx tessl i pantheon-ai/typescript-advanced@0.1.1references