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
Generic type guards provide reusable, type-safe narrowing functions that work across different types.
function isArray<T>(value: T | T[]): value is T[] {
return Array.isArray(value);
}
const value: string | string[] = getSomeValue();
if (isArray(value)) {
// value is narrowed to string[]
value.map(s => s.toUpperCase());
}function hasProperty<T, K extends string>(
obj: T,
key: K
): obj is T & Record<K, unknown> {
return typeof obj === "object" && obj !== null && key in obj;
}
const data: unknown = { name: "Alice", age: 30 };
if (hasProperty(data, "name")) {
// data is narrowed to have name property
console.log(data.name);
}function isInstance<T>(
value: unknown,
constructor: new (...args: any[]) => T
): value is T {
return value instanceof constructor;
}
const val: unknown = new Date();
if (isInstance(val, Date)) {
// val is narrowed to Date
console.log(val.getTime());
}function isArrayOf<T>(
value: unknown,
guard: (item: unknown) => item is T
): value is T[] {
return Array.isArray(value) && value.every(guard);
}
function isString(value: unknown): value is string {
return typeof value === "string";
}
const data: unknown = ["a", "b", "c"];
if (isArrayOf(data, isString)) {
// data is narrowed to string[]
data.forEach(s => console.log(s.toUpperCase()));
}function isDefined<T>(value: T | undefined | null): value is T {
return value !== undefined && value !== null;
}
const values = [1, undefined, 2, null, 3];
const defined = values.filter(isDefined); // number[]type TypeMap = {
string: string;
number: number;
boolean: boolean;
};
function isType<K extends keyof TypeMap>(
value: unknown,
type: K
): value is TypeMap[K] {
return typeof value === type;
}
const val: unknown = "hello";
if (isType(val, "string")) {
// val is narrowed to string
console.log(val.toUpperCase());
}Install with Tessl CLI
npx tessl i pantheon-ai/typescript-advancedreferences