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
Creates a type by picking specific properties from T.
interface User {
id: string;
name: string;
email: string;
password: string;
createdAt: Date;
}
type PublicUser = Pick<User, 'id' | 'name' | 'email'>;
// {
// id: string;
// name: string;
// email: string;
// }
function displayUser(user: PublicUser) {
// Only id, name, email accessible
console.log(user.name);
// console.log(user.password); // ❌ Error
}type Pick<T, K extends keyof T> = {
[P in K]: T[P];
};API Response DTOs
interface DbUser {
id: string;
name: string;
email: string;
passwordHash: string;
salt: string;
createdAt: Date;
updatedAt: Date;
}
type UserResponse = Pick<DbUser, 'id' | 'name' | 'email' | 'createdAt'>;
function getUserById(id: string): UserResponse {
const dbUser = db.users.findById(id);
return {
id: dbUser.id,
name: dbUser.name,
email: dbUser.email,
createdAt: dbUser.createdAt
};
}Form Fields
interface Product {
id: string;
name: string;
description: string;
price: number;
stock: number;
createdAt: Date;
}
type ProductFormData = Pick<Product, 'name' | 'description' | 'price' | 'stock'>;
function ProductForm() {
const [formData, setFormData] = useState<ProductFormData>({
name: '',
description: '',
price: 0,
stock: 0
});
}Minimal Interface
interface TodoItem {
id: string;
title: string;
description: string;
completed: boolean;
createdAt: Date;
updatedAt: Date;
tags: string[];
}
type TodoSummary = Pick<TodoItem, 'id' | 'title' | 'completed'>;
function getTodoList(): TodoSummary[] {
// Return minimal data for list view
}Creates a type by omitting specific properties from T.
interface User {
id: string;
name: string;
email: string;
password: string;
}
type UserWithoutPassword = Omit<User, 'password'>;
// {
// id: string;
// name: string;
// email: string;
// }
type PublicUser = Omit<User, 'password' | 'email'>;
// {
// id: string;
// name: string;
// }type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;Note: K is keyof any (not keyof T), allowing omitting keys that don't exist.
Remove Sensitive Data
interface Employee {
id: string;
name: string;
email: string;
salary: number;
ssn: string;
}
type PublicEmployee = Omit<Employee, 'salary' | 'ssn'>;
function getEmployeeProfile(id: string): PublicEmployee {
const employee = db.employees.findById(id);
const { salary, ssn, ...public } = employee;
return public;
}Exclude Auto-Generated Fields
interface DbRecord {
id: string;
createdAt: Date;
updatedAt: Date;
data: any;
}
type CreateRecordInput = Omit<DbRecord, 'id' | 'createdAt' | 'updatedAt'>;
async function createRecord(input: CreateRecordInput): Promise<DbRecord> {
return db.records.create({
...input,
id: generateId(),
createdAt: new Date(),
updatedAt: new Date()
});
}Extend and Modify
interface BaseConfig {
host: string;
port: number;
timeout: number;
}
// Replace timeout with different type
interface ExtendedConfig extends Omit<BaseConfig, 'timeout'> {
timeout: {
connect: number;
read: number;
};
}
const config: ExtendedConfig = {
host: 'localhost',
port: 3000,
timeout: {
connect: 5000,
read: 30000
}
};Choose based on which is more concise:
interface LargeType {
a: string;
b: number;
c: boolean;
d: Date;
e: string[];
f: object;
}
// If you need most properties, use Omit
type MostProps = Omit<LargeType, 'f'>;
// If you need few properties, use Pick
type FewProps = Pick<LargeType, 'a' | 'b'>;type ModifyProp<T, K extends keyof T, NewType> =
Omit<T, K> & Record<K, NewType>;
interface User {
id: string;
name: string;
age: number;
}
// Change age from number to string
type UserWithStringAge = ModifyProp<User, 'age', string>;
// {
// id: string;
// name: string;
// age: string;
// }type PickOptional<T, K extends keyof T> =
Pick<T, K> & Partial<Omit<T, K>>;
interface Config {
host: string;
port: number;
ssl: boolean;
timeout: number;
}
// host and port required, others optional
type MinimalConfig = PickOptional<Config, 'host' | 'port'>;
// {
// host: string;
// port: number;
// ssl?: boolean;
// timeout?: number;
// }interface DbUser {
id: string;
username: string;
email: string;
passwordHash: string;
role: string;
}
// Public API response
type UserDto = Omit<DbUser, 'passwordHash'>;
// Create user input
type CreateUserDto = Omit<DbUser, 'id'>;
// Update user input
type UpdateUserDto = Partial<Omit<DbUser, 'id' | 'passwordHash'>>;interface Article {
id: string;
title: string;
content: string;
authorId: string;
publishedAt: Date | null;
createdAt: Date;
}
type ArticleFormData = Pick<Article, 'title' | 'content'>;
type ArticleCreateData = Omit<Article, 'id' | 'createdAt'>;Install with Tessl CLI
npx tessl i pantheon-ai/typescript-advanced@0.1.1references