---
title: "VariantFamily: interface in Variants, TypeShade API"
description: "VariantFamily, an interface in Variants. A built family. Feature axes as one family of modules, compiled and linked point by point."
url: https://typeshade.dev/api/variantfamily-interface/
language: en
---

# `VariantFamily`

Interface in Variants

A built family.

`import type { VariantFamily } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
interface VariantFamily<A extends Record<string, readonly unknown[]>> {
  readonly variants: readonly Variant<A>[];
  readonly keys: readonly string[];
  get(key: string): Variant<A> | undefined;
  emit(target: 'wgsl', opts?: EmitOptions): ReadonlyMap<string, string>;
  emit( target: 'glsl-es300', opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }, ): ReadonlyMap<string, string>;
  emitGuarded( defines: GuardDefines<A>, opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }, ): string;
  emitGuardedFragment( defines: GuardDefines<A>, opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }, ): EmitFragment;
}
```

## Instance properties

**`variants` read only `readonly Variant<A>[]`**

**`keys` read only `readonly string[]`**

Every key, in `variants` order: the id set a pipeline cache keys its programs by.

## Instance methods

**`get` `(key: string): Variant<A> | undefined`**

Look one variant up by key; `undefined` when the key names no variant.

**`emit` `(target: 'wgsl', opts?: EmitOptions): ReadonlyMap<string, string>`**

One preprocessor-free source per key. The only shape WGSL can take, and the one a pipeline cache should prefer on GLSL too.

**`emit` `(target: 'glsl-es300', opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }): ReadonlyMap<string, string>`**

**`emitGuarded` `(defines: GuardDefines<A>, opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }): string`**

One GLSL source whose arms are selected by preprocessor defines the host owns.

Opt in to this when the host already sets the define per draw and cannot pick a source per variant; otherwise prefer [`VariantFamily.emit`](https://typeshade.dev/api/variantfamily-interface/). GLSL only, because the arms are selected by the GLSL preprocessor. Every arm is byte-identical to the corresponding `emit()` source, so a program selected through the ladder is the same program as the standalone variant.

**`emitGuardedFragment` `(defines: GuardDefines<A>, opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }): EmitFragment`**

The same generated ladder as [`VariantFamily.emitGuarded`](https://typeshade.dev/api/variantfamily-interface/), returned as a header-less fragment for a host that owns the program and composes these declarations into it.

`emitGuarded` returns a whole stage, preamble included. A ladder pasted into a host program through an `#include` cannot carry a second `#version`, so here the preamble comes back as data, exactly as [`emitGlslFragment`](https://typeshade.dev/api/emitglslfragment/) returns it, and `[...preamble, '', source].join('\n')` reproduces `emitGuarded`’s output byte for byte.

`declares` and `requires` are the union across the arms, since the host’s preprocessor picks the arm and the composer cannot know which: every name any arm declares is one the host’s prelude must not collide with, and every symbol any arm needs is one the host must provide. Throws for a preamble mismatch exactly as `emitGuarded` does.

## See also

- [`emitGlslFragment`](https://typeshade.dev/api/emitglslfragment/)

## Source

[`src/core/variant-family.ts`, line 79](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/variant-family.ts#L79), at commit af54ddad5
