From 96f8d68df4e20c9f9b770cad2b78fb04314fffbd Mon Sep 17 00:00:00 2001 From: Ian Obermiller Date: Sat, 31 Jul 2021 09:14:40 -0400 Subject: [PATCH] Export `Simplify` type (#238) --- base.d.ts | 1 + readme.md | 1 + source/simplify.d.ts | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/base.d.ts b/base.d.ts index a3e8a64cb..99bebb001 100644 --- a/base.d.ts +++ b/base.d.ts @@ -35,6 +35,7 @@ export {Entry} from './source/entry'; export {Entries} from './source/entries'; export {SetReturnType} from './source/set-return-type'; export {Asyncify} from './source/asyncify'; +export {Simplify} from './source/simplify'; // Miscellaneous export {PackageJson} from './source/package-json'; diff --git a/readme.md b/readme.md index 34b034cc4..7164a563d 100644 --- a/readme.md +++ b/readme.md @@ -119,6 +119,7 @@ Click the type names for complete docs. - [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection. - [`SetReturnType`](source/set-return-type.d.ts) - Create a function type with a return type of your choice and the same parameters as the given function type. - [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type. +- [`Simplify`](source/simplify.d.ts) - Flatten the type output to improve type hints shown in editors. ### Template literal types diff --git a/source/simplify.d.ts b/source/simplify.d.ts index 5e067c24e..32558b7bd 100644 --- a/source/simplify.d.ts +++ b/source/simplify.d.ts @@ -1,4 +1,24 @@ /** Flatten the type output to improve type hints shown in editors. + +@example +``` +import {Simplify} from 'type-fest'; + +type PositionProps = { + top: number; + left: number; +}; + +type SizeProps = { + width: number; + height: number; +}; + +// In your editor, hovering over `Props` will show a flattened object with all the properties. +type Props = Simplify; +``` + +@category Utilities */ export type Simplify = {[KeyType in keyof T]: T[KeyType]};