# atom.io/foundations/type-utils

Source: docs/source/pages/docs/foundations/type-utils.mdx
URL: /docs/foundations/type-utils

# <low-emphasis>atom.io</low-emphasis>/foundations/type-utils

Small reusable type helpers that make inferred types easier to read
or expose readonly views of mutable shapes.

Import these helpers from `atom.io/foundations/type-utils`.

## package contents

<table-wrapper>

| Export | Description |
| --- | --- |
| `DeepReadonly` | Recursively derive a readonly view of an object or collection. |
| `Flat` | Flatten a mapped object type into a readable object shape. |
| `ViewOf` | Derive the readonly view type of arrays, maps, sets, and transceivers. |

</table-wrapper>

## DeepReadonly

`DeepReadonly` recursively marks object properties as readonly, converts arrays,
maps, and sets to their readonly forms, and leaves functions callable.

### deep readonly
Source: docs/source/exhibits/foundations/type-utils/deep-readonly.ts

```ts
import type { DeepReadonly } from "atom.io/foundations/type-utils"

type DocumentView = DeepReadonly<{
	metadata: { author: string }
	pages: string[]
}>

declare const document: DocumentView

document.metadata.author // string; assignment is forbidden
document.pages // readonly string[]
```

## Flat

`Flat` is mostly for type display and type composition.

### flat
Source: docs/source/exhibits/foundations/type-utils/flat.ts

```ts
import type { Flat } from "atom.io/foundations/type-utils"

type Intersected = { id: string } & { done: boolean }
type Readable = Flat<Intersected>

type Expected = {
	id: string
	done: boolean
}
```

## ViewOf

`ViewOf` converts common mutable containers into readonly views. If a type declares a
`READONLY_VIEW` marker, `ViewOf` uses that marker.

### view of
Source: docs/source/exhibits/foundations/type-utils/view-of.ts

```ts
import type { ViewOf } from "atom.io/foundations/type-utils"

type ListView = ViewOf<string[]> // readonly string[]
type SetView = ViewOf<Set<string>> // ReadonlySet<string>
```
