---
title: "toDTCG"
description: "Exports a compiled theme, a published theme component, or the init behind either one to W3C DTCG 2025.10 documents."
url: "https://pitlane.tools/package/theme/dtcg/function/toDTCG"
---

# toDTCG

```ts
import { toDTCG } from "@pitlane/theme/dtcg";
```

```ts
function toDTCG<T>(theme): DTCGExport;
```

Exports a compiled theme, a published theme component, or the init behind either one to W3C DTCG 2025.10 documents.

An export places `$type` on the lowest group whose complete descendant set has one expressible type; standard tokens below that group omit the redundant `$type`. Mixed groups put `$type` on their standard token leaves instead. Exact `var(--token-name)` values are converted back to `{token.path}` using the collector's variable-name map.

DTCG cannot represent all CSS values this package accepts. Inexpressible values are preserved in `$extensions["tools.pitlane"]` as `{ type, value, reason }`, on an extension-only node with no `$value`; this keeps the standard document valid while preserving the original value for a caller that reports or handles the loss. `inexpressible` counts those nodes in the base document and every mode document.

DTCG descriptions, deprecation metadata, and unrelated extensions are not in the authoring format and cannot be recovered.

## Type Parameters

### T

`T`

## Parameters

### theme

| [`ThemeInit`](https://pitlane.tools/package/theme/interface/ThemeInit.md) | [`ThemeComponent`](https://pitlane.tools/package/theme/interface/ThemeComponent.md)\<`T`> | [`ThemeResult`](https://pitlane.tools/package/theme/interface/ThemeResult.md)\<`T`>

A [ThemeResult](https://pitlane.tools/package/theme/interface/ThemeResult.md), its [ThemeComponent](https://pitlane.tools/package/theme/interface/ThemeComponent.md), or its init

## Returns

[`DTCGExport`](https://pitlane.tools/package/theme/dtcg/interface/DTCGExport.md)

The base document, one partial document per mode, and the lossy-value count

## Throws

ThemeError when the supplied init has an invalid token/schema structure

## Example

```ts
import { createTheme } from "@pitlane/theme";
import { toDTCG } from "@pitlane/theme/dtcg";
import * as s from "@pitlane/theme/schema";

let theme = createTheme({
    schema: { color: s.color() },
    tokens: { color: { white: "#fff" } },
});
let { document, inexpressible } = toDTCG(theme);
```
