DT
DevlogsGardenWritingProjectsActivityAbout
Back to devlog
Oct 26, 2023 Sage 1 min read

TypeScript Tricks I Love

#typescript#frontend#coding

TypeScript has a few utility types that I find myself using in almost every project.

Partial and Pick

Sometimes you only want a subset of a type.

typescript
interface User { id: string; name: string; email: string; role: 'admin' | 'user'; } // Only need id and email for this function function sendEmail(user: Pick<User, 'id' | 'email'>) { console.log(`Sending to ${user.email}`); }

Advanced Generic Constraints

You can enforce that a generic type must have certain properties.

typescript
function getKey<T extends object, K extends keyof T>(obj: T, key: K) { return obj[key]; } const user = { name: "Sage", age: 30 }; const name = getKey(user, "name"); // Valid // const fail = getKey(user, "address"); // Error: Argument of type '"address"' is not assignable...
Previous
Polishing the UI
Next
Untitled

On this page

Partial and PickAdvanced Generic Constraints

Weekly Recap

No spam, just vibes.

Welcome to the recap!
build: b80930c|updated: 2025-12-11
© 2025 Dean Tarisai