
*By Sean Erick C. Ramones, Vue SME | JavaScript/TypeScript SME*
Sean Erick C. Ramones
TypeScript has become the default choice for building scalable JavaScript applications. While most developers are familiar with its basic features such as static typing, interfaces, and generics, TypeScript also includes lesser-known but powerful features that can significantly improve developer experience, reduce boilerplate, and make applications safer.
This report highlights several of these "hidden gems" in TypeScript and explains how they can be applied in real-world projects.
TypeScript ships with a rich set of utility types that are often overlooked. Some of the most useful include:
Partial<T> – Makes all properties optionalPick<T, K> – Selects a subset of propertiesOmit<T, K> – Removes certain propertiesRecord<K, T> – Defines key-value mapsinterface User {
id: string;
name: string;
email: string;
}
type UpdateUser = Partial<Omit<User, "id">>;
Why it matters: Cuts down on boilerplate when working with complex data models.
Introduced in TypeScript 4.9, satisfies ensures an object conforms to a type without widening its type unnecessarily.
type Role = "admin" | "manager" | "employee";
const userRoles = {
alice: "admin",
bob: "manager",
} satisfies Record<string, Role>;
Why it matters: Provides the best of both worlds—type safety and accurate inference.
Template literal types allow the creation of string patterns that are type-safe.
type EventName = `on${Capitalize<string>}`;
const clickEvent: EventName = "onClick"; // ✅
const wrongEvent: EventName = "click"; // ❌
Why it matters: Great for enforcing naming conventions and API consistency.
TypeScript unions can be paired with never to ensure that all cases are handled.
type Shape =
| { kind: "circle"; radius: number }
| { kind: "square"; size: number };
function area(shape: Shape): number {
switch (shape.kind) {
case "circle":
return Math.PI * shape.radius ** 2;
case "square":
return shape.size * shape.size;
default:
const _exhaustive: never = shape;
return _exhaustive;
}
}
Why it matters: Prevents missing cases when working with unions.
You can freeze nested structures into immutable literal types:
const THEMES = {
light: { background: "#fff", text: "#000" },
dark: { background: "#000", text: "#fff" },
} as const;
type Theme = keyof typeof THEMES;
Why it matters: Helps in theming, configuration, and role-based design systems.
These features,const assertions, utility types, satisfies, template literal types, discriminated unions, and literal inference demonstrate how TypeScript goes beyond "just typing variables." By applying them, teams can achieve:
Mastering these lesser-known features allows developers to take full advantage of TypeScript, leading to more reliable and maintainable applications.