# DTO Source: [`lib/dto.d.ts`](../../lib/dto.d.ts) Turns any type into a plain Data Transfer Object shape: strips function properties and symbol-keyed properties, and always deep-processes nested objects and arrays (there's no shallow/`Deep` variant — `DTO` behaves like the `Deeper*` members of [the convention](../api.md#the-deep--deeper-convention)). Tuples are left untouched, same as everywhere else in the library. ## `DTO` ```ts import type { DTO } from 'ts-gems'; interface User { name: string; age?: number; greet(): void; // function - removed [Symbol.iterator]: () => Iterator; // symbol key - removed } type UserDTO = DTO; // { name: string; age?: number } ``` Nested objects and arrays are always processed, recursively: ```ts interface Order { id: string; createdBy: { name: string; greet(): void }; items: { sku: string; validate(): boolean }[]; } type OrderDTO = DTO; // { // id: string; // createdBy: { name: string }; // items: { sku: string }[]; // } ``` ### The `X` parameter The second type parameter, `X`, is unioned into **every** remaining property's value type (through `NonNullable`, applied at every nesting level). This is handy for tagging every field of the DTO with a shared extra type — for example, a sentinel used to represent "field explicitly not selected" in a partial-response GraphQL/RPC layer: ```ts import type { DTO } from 'ts-gems'; const NOT_SELECTED = Symbol('not-selected'); type NotSelected = typeof NOT_SELECTED; interface User { name: string; age?: number; } type SparseUserDTO = DTO; // { name: string | NotSelected; age?: number | NotSelected } ``` > Because `X` is combined via `NonNullable`, passing `null` or > `undefined` as `X` has no visible effect — both are immediately stripped > again. Use a non-nullish sentinel (a literal, a branded/[`Opaque`](opaque.md) > type, or a `unique symbol` as above) if you need one. ## `PartialDTO` ```ts type PartialDTO = DeeperPartial>; ``` `DTO` with every property (including nested ones and array elements) made optional via [`DeeperPartial`](partial.md#deeperpartialt) — a common shape for "create" endpoint request bodies where every field may be omitted. ```ts import type { PartialDTO } from 'ts-gems'; interface User { name: string; profile: { bio: string }; } type CreateUserBody = PartialDTO; // { name?: string; profile?: { bio?: string } } ``` ## `PatchDTO` ```ts type PatchDTO = DeeperNullish>; ``` `DTO` with every property (including nested ones and array elements) made optional **and** nullable via [`DeeperNullish`](nullish.md#deepernullisht) — a common shape for "patch"/"update" endpoint request bodies, where `null` means "clear this field" and omitting the key means "leave it unchanged". ```ts import type { PatchDTO } from 'ts-gems'; interface User { name: string; profile: { bio: string }; } type UpdateUserBody = PatchDTO; // { name?: string | null; profile?: { bio?: string | null } | null } ```