diff --git a/cli/cmd.ts b/cli/cmd.ts index 8196c25..1d22c03 100644 --- a/cli/cmd.ts +++ b/cli/cmd.ts @@ -1,4 +1,4 @@ -import type { Intersect } from "../ts/types.ts"; +import type { Pretty } from "../ts/types.ts"; export type CmdOptions = { cwd?: string; @@ -6,7 +6,7 @@ export type CmdOptions = { fullResult?: boolean; }; -export type CmdResult = Intersect< +export type CmdResult = Pretty< & Pick & { stdout: string; stderr: string } >; diff --git a/md/codeBlock/fenced.ts b/md/codeBlock/fenced.ts index 9b25c1f..80a6fd9 100644 --- a/md/codeBlock/fenced.ts +++ b/md/codeBlock/fenced.ts @@ -1,9 +1,9 @@ import { mostConsecutive } from "../../string/sequence.ts"; -import type { Intersect } from "../../ts/types.ts"; +import type { Pretty } from "../../ts/types.ts"; import * as infoString from "./infoString.ts"; import { FENCED_CODE_BLOCK_REGEX } from "./regex.ts"; -export type FencedCodeBlockDetails = Intersect< +export type FencedCodeBlockDetails = Pretty< & { type: "fenced"; char: FenceChar; @@ -15,7 +15,7 @@ export type FencedCodeBlockDetails = Intersect< export type FenceChar = "`" | "~"; -export type CreateFencedOptions = Intersect< +export type CreateFencedOptions = Pretty< & { /** If `lang` or `meta` contain backticks, `char` will be set to "~" and * this option will be ignored. */ diff --git a/readme.md b/readme.md index 90753bc..dc831cf 100644 --- a/readme.md +++ b/readme.md @@ -289,3 +289,13 @@ import { evaluate } from "https://deno.land/x/handy/ts/utils.ts"; await evaluate("console.log('Hello!')") .then((res) => res.stdout); // "Hello!" ``` + +```ts +import type { Pretty } from "https://deno.land/x/handy/ts/types.ts"; + +type Input = { a: number } & { b: string }; +// ^? { a: number } & { b: string } + +type Prettified = Pretty; +// ^? { a: number; b: string } +``` diff --git a/ts/evaluate.ts b/ts/evaluate.ts index 74b643d..fafa449 100644 --- a/ts/evaluate.ts +++ b/ts/evaluate.ts @@ -1,7 +1,7 @@ import { cmd, CmdOptions, CmdResult } from "../cli/cmd.ts"; -import type { Intersect } from "./types.ts"; +import type { Pretty } from "./types.ts"; -export type EvaluateTypeScriptOptions = Intersect< +export type EvaluateTypeScriptOptions = Pretty< & Pick & { typeCheck?: boolean } >; diff --git a/ts/types.ts b/ts/types.ts index ca8d5b4..fad2da0 100644 --- a/ts/types.ts +++ b/ts/types.ts @@ -1,12 +1,15 @@ -/** Represent an object type with all properties merged into the top level, - * handling intersections (`&`). +/** Represents a type with all properties merged into the top level, handling + * intersections (`&`), often resulting in more legible shapes particularly + * for object types. + * + * Source: https://twitter.com/mattpocockuk/status/1622730173446557697 * * @example * type USCity = { city: string, state: string }; * type USAddress = USCity & { street: string, zip: string }; * // ^? USCity & { street: string, zip: string } * - * type USAddress = Intersect; + * type USAddress = Pretty; * // ^? { city: string, state: string, street: string, zip: string } */ -// deno-lint-ignore no-explicit-any -export type Intersect> = { [K in keyof T]: T[K] }; +// deno-lint-ignore ban-types +export type Pretty = { [K in keyof T]: T[K] } & {};