ts-hover-prettify
v1.1.2
Published
Utility to make the hover of a typescript object more readable
Readme
ts-hover-prettify
Provide Prettify<T> so TypeScript hovers show a single object shape instead of a chain of intersections.
What is this?
This package exports the Prettify<T> utility type for projects where you want the type in source control or need tsc / CI without the VS Code extension. The extension injects the same type automatically — pick one approach per repo.
The mapped-type pattern only affects how TypeScript prints types in the language service. It is erased at compile time and does not change JavaScript output.
Quick Start
pnpm add -D ts-hover-prettify
# npm add -D ts-hover-prettify
# yarn add -D ts-hover-prettifyGlobal Prettify (recommended)
Create a declaration file included by your tsconfig.json, for example prettify.d.ts:
import "ts-hover-prettify/global";Add it to compilerOptions.types, or to top-level include / files:
{
"include": ["src/**/*", "prettify.d.ts"]
}After that, Prettify is available everywhere in the project without importing it in each file.
Named import
import type { Prettify } from "ts-hover-prettify";
type Flat = Prettify<{ x: 1 } & { y: 2 }>;Example
type Intersected = { a: string } & { b: number } & { c: boolean };
// Hover: { a: string; } & { b: number; } & { c: boolean; }
type Readable = Prettify<
{ a: string } & { b: number } & { c: boolean }
>;
// Hover: { a: string; b: number; c: boolean; }Working example in this repo: examples/intersected-types-npm. Verify from the repo root:
pnpm verify:example-npmAPI
export type Prettify<T> = {
[K in keyof T]: T[K];
} & {};Implementation matches the common community pattern (also documented as Compute, Expand, etc.).
Behaviour and limits
- Wrap only the types where you care about hover readability. Unwrapped aliases keep their default display.
- Works best on object intersections and similar shapes you intentionally pass into
Prettify. It does not recursively “fix” every nested type in the project. - Requires TypeScript (peer usage via your project’s
typescriptversion). This package ships type definitions only; it does not patch the compiler.
VS Code / Cursor without npm
Use the ts-hover-prettify-vscode extension instead of this package if you only need editor hovers and accept workspace injection of .vscode/ts-hover-prettify.d.ts.
Documentation
| Resource | Description | |----------|-------------| | Root README | Monorepo overview and install options | | Extension README | Zero-config editor setup | | CHANGELOG.md | Package release notes |
Contributing
Issues and pull requests are welcome on GitHub.
License
MIT — Copyright 2023 Marco Antolini.
