ts-prettify
v1.0.1
Published
A TypeScript type helper to prettify complex type visualizations in libraries and documentation.
Readme
ts-prettify
A TypeScript type helper to prettify complex type visualizations in libraries and documentation.
Overview
ts-prettify provides a utility type that simplifies and flattens complex TypeScript types, making them easier to read in IDE tooltips and generated documentation. This is especially useful for library authors who want to improve the developer experience.
Installation
npm install ts-prettifyUsage
import type { Prettify } from 'ts-prettify';
type ComplexType = {
foo: string;
bar: { baz: number; qux: boolean };
// ...more properties...
};
// Prettify flattens intersections/unions and expands mapped types for better readability
type PrettyType = Prettify<ComplexType>;Example
Before:
type Result = A & B & { extra: string };
// Tooltip shows nested intersections and mapped typesAfter:
type Result = Prettify<A & B & { extra: string }>;
// Tooltip shows a flattened, expanded typeAPI
Prettify<T>
Expands and flattens the type T for improved visualization.
Why?
TypeScript often displays complex types as deeply nested or with intersections/unions that are hard to read. Prettify helps present these types in a more readable, expanded form.
License
MIT
