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
Type assertions tell TypeScript to treat a value as a specific type.
const value: unknown = "hello";
const strLength = (value as string).length;
// DOM elements
const input = document.querySelector('input') as HTMLInputElement;
input.value = 'text';const value: unknown = "hello";
const strLength = (<string>value).length;Note: Use as syntax - it works in JSX/TSX files.
function getUser(id: string) {
const user = users.find(u => u.id === id);
// Assert user is not null/undefined
return user!.name;
}
// Optional chaining is safer
return users.find(u => u.id === id)?.name;Warning: Only use ! when you're certain the value exists. Prefer optional chaining.
// Infer literal types instead of widening
const config = {
endpoint: '/api/users',
method: 'GET'
} as const;
// Type: { readonly endpoint: "/api/users"; readonly method: "GET"; }
// Array becomes readonly tuple
const colors = ['red', 'green', 'blue'] as const;
// Type: readonly ["red", "green", "blue"]
// Use in function parameters
function request<T extends string>(method: T) {
// method is the literal type, not string
}
request(config.method); // ✅ method is "GET"// Validate type without widening
const config = {
endpoint: '/api/users',
method: 'GET',
timeout: 5000
} satisfies Config;
// config.method is still "GET", not string
// Unlike 'as Config', satisfies preserves literal types
type Color = { r: number; g: number; b: number } | string;
const palette = {
red: { r: 255, g: 0, b: 0 },
blue: '#0000FF'
} satisfies Record<string, Color>;
// palette.red.r is accessible (object structure preserved)
// With 'as Record<string, Color>', red.r would errorTypeScript uses structural typing (shape-based).
interface Point {
x: number;
y: number;
}
class Point2D {
constructor(public x: number, public y: number) {}
}
const point: Point = new Point2D(10, 20); // ✅ Compatibletype Handler = (msg: string, code: number) => void;
// ✅ Fewer parameters is compatible
const handler: Handler = (msg: string) => {
console.log(msg);
};
// ❌ More parameters is not compatible
const handler2: Handler = (msg: string, code: number, extra: boolean) => {};interface Animal { name: string; }
interface Dog extends Animal { breed: string; }
class Vet {
treat(animal: Animal) {}
}
class DogVet extends Vet {
// ⚠️ Allowed but unsound
treat(dog: Dog) {}
}satisfies for validation without widening - Preserves literal typesas const for immutable literal typesvalue as unknown as TargetType indicates design issueas - Defeats type checking, prefer narrowingInstall with Tessl CLI
npx tessl i pantheon-ai/typescript-advanced@0.1.1references