# @portabletext/types

> Shared TypeScript definitions for core Portable Text data structures

Latest version **4.0.2** (published 2026-03-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @portabletext/types
pnpm add @portabletext/types
yarn add @portabletext/types
bun add @portabletext/types
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.2 |
| Published | 2026-03-04 |
| First published | 2022-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=20.19 <22 \|\| >=22.12 |
| Dependencies | 0 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 20 |
| Author | Sanity.io |
| Maintainers | kmelve, rexxars, skogsmaskin, mariuslundgard, bjoerge, rbotten, sanity-io, snorreeb, josef-sanity, stipsan, christianhg |
| Keywords | portable-text |

## Links

- npm: https://www.npmjs.com/package/@portabletext/types
- Repository: https://github.com/portabletext/types
- Homepage: https://github.com/portabletext/types#readme
- Issues: https://github.com/portabletext/types/issues
- npm.io page: https://npm.io/package/@portabletext/types

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 4.0.2 (latest) — 2026-03-04
- 2.0.14-canary.0 (canary) — 2024-04-18
- 4.0.1 — 2025-12-31
- 4.0.0 — 2025-12-09
- 3.0.1 — 2025-12-09
- 3.0.0 — 2025-11-04
- 2.0.15 — 2025-08-21
- 2.0.14 — 2025-08-21
- 2.0.13 — 2024-04-10
- 2.0.12 — 2024-04-05
- 2.0.11 — 2024-03-20
- 2.0.10 — 2024-03-18
- 2.0.9 — 2024-03-16
- 2.0.8 — 2023-10-10
- 2.0.7 — 2023-09-28
- … 11 more at https://npm.io/package/@portabletext/types/versions

## README

# @portabletext/types

[![npm version](https://img.shields.io/npm/v/@portabletext/types.svg?style=flat-square)](https://www.npmjs.com/package/@portabletext/types)[![Build Status](https://img.shields.io/github/actions/workflow/status/portabletext/types/main.yml?branch=main&style=flat-square)](https://github.com/portabletext/types/actions?query=workflow%3Atest)

TypeScript types for Portable Text

## Installation

```
npm install --save @portabletext/types
```

## Documentation

See [https://portabletext.github.io/types/](https://portabletext.github.io/types/)

## Usage

```ts
import type {
  PortableTextBlock,
  PortableTextSpan,
  PortableTextLink
} from '@portabletext/types'

const headingSpan: PortableTextSpan = {
  _type: 'span',
  _key: '5p4n',
  text: 'A simple Portable Text heading block',
  marks: [],
}

const myBlocks: PortableTextBlock[] = [
  {
    _type: 'block',
    _key: 'abc123',
    style: 'h1',
    children: [headingSpan],
    markDefs: [],
  },
  {
    _type: 'block',
    _key: 'xyz987',
    style: 'normal',
    children: [
      {_type: 'span', _key: 'c7', text: 'Check out the ', marks: []}
      {_type: 'span', _key: 'x2', text: 'TypeScript definitions', marks: ['m4hl1nk']},
      {_type: 'span', _key: 'u5', text: ' if you are using TS!', marks: []}
    ],
    markDefs: [
      {
        _key: 'm4hl1nk',
        _type: 'link',
        href: 'https://github.com/portabletext/types'
      }
    ],
  },
]

/**
 * Very specific Portable Text block, where:
 * - Only link and author references (custom) are allowed as marks
 * - Only Portable Text spans and `localCurrency` objects can be inline children
 * - Blocks can only be of style `normal` or `call-to-action` (custom)
 * - List items can only be of type `bullet`
 */
type MyCustomBlock = PortableTextListItemBlock<
  PortableTextLink | AuthorReference, // `M`: Marks
  PortableTextSpan | LocalCurrency,   // `C`: Children
  'normal' | 'call-to-action',        // `S`: Styles
  'bullet'                            // `L`: List item types
>
```

## License

MIT © [Sanity.io](https://www.sanity.io/)

---
_Source: https://npm.io/package/@portabletext/types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
