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 guards are TypeScript constructs that allow narrowing types within conditional blocks using runtime checks.
function processValue(value: string | number) {
if (typeof value === "string") {
// value is narrowed to string
return value.toUpperCase();
}
// value is narrowed to number
return value.toFixed(2);
}class Dog {
bark() { console.log("Woof!"); }
}
class Cat {
meow() { console.log("Meow!"); }
}
function makeSound(animal: Dog | Cat) {
if (animal instanceof Dog) {
animal.bark();
} else {
animal.meow();
}
}interface Fish {
swim: () => void;
}
interface Bird {
fly: () => void;
}
function move(animal: Fish | Bird) {
if ("swim" in animal) {
animal.swim();
} else {
animal.fly();
}
}function printLength(str: string | null) {
if (str) {
// str is narrowed to string
console.log(str.length);
} else {
// str is null
console.log("No string provided");
}
}function example(x: string | number, y: string | boolean) {
if (x === y) {
// x and y are both narrowed to string
x.toUpperCase();
y.toUpperCase();
}
}Install with Tessl CLI
npx tessl i pantheon-ai/typescript-advancedreferences