Prettier merged type
When working with intersection types in TypeScript, you might have noticed that hovering over the type doesn't show the complete expanded version. Here's a common example:
type Person = {
name: string;
age: string;
};
type Developer = Person & {
tech: string;
};Hovering over Developer in your IDE will typically show something like Person & { tech: string } rather than the complete flattened type.
This can be frustrating when you want to see all properties at once.
Here's a handy utility type that forces TypeScript to show the expanded version:
type Prettify<T> = {
[K in keyof T]: T[K];
} & {};Now let's apply it to our Developer type:
type Developer = Prettify<
Person & {
tech: string;
}
>;
// Hovering now shows the complete type:
type Developer = {
name: string;
age: string;
tech: string;
};This approach works seamlessly with all TypeScript utility types like Pick, Omit, etc.:
type OmitPerson = Prettify<
Omit<Developer, "tech" | "age"> & {
email: string;
}
>;
// Hovering now shows the complete type:
type OmitPerson = {
name: string;
email: string;
};This is particularly useful when:
- Debugging complex types
- Working with large intersection types
- Sharing code with team members who need to understand your types quickly
Related Posts
Find more posts like this one.

January 10, 2024
I'm Done Typing npm
Are you tired of typing npm?
Read more
May 29, 2025
Load balancer RPC endpoints
Did your Dapp cash because of RPC endpoint?
Read more
May 15, 2025
Solidity: Storage Slots of Complex Types
This article explains how Solidity stores smart contract data using storage slots, packing for efficiency, and Yul assembly for direct storage access
Read more
May 13, 2025
Solidity: Storage Slots of Primary Types
This article explains how Solidity stores smart contract data using storage slots, packing for efficiency, and Yul assembly for direct storage access
Read more
May 13, 2025
Cache Strategies
Cache strategies are a way to improve the performance of a system.
Read more
May 9, 2025
Load Balancer
A load balancer is a device that distributes network traffic between multiple servers
Read more
May 9, 2025
Rate Limiting
Rate limiting is a technique used to control the rate of requests to a service.
Read more
May 13, 2025
Redis
Redis is an open-source, in-memory data structure store used as a database, cache, and message broker.
Read more
May 19, 2025
Javascript: deep cloning object methods
Read more
January 5, 2025
Should we use type or interface in typescript
Read more