---
title: "linkVariants(): function in Variants, TypeShade API"
description: "linkVariants, a function in Variants. Emit, compile and link every variant of a family on a real WebGL2 context."
url: https://typeshade.dev/api/linkvariants/
language: en
---

# `linkVariants()`

Function in Variants

Emit, compile and link every variant of a family on a real WebGL2 context.

`import { linkVariants } from 'typeshade'`

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

## Syntax

```ts
function linkVariants<A extends Record<string, readonly unknown[]>>(
  gl: GlLinker,
  family: VariantFamily<A>,
  opts?: EmitOptions,
): readonly VariantLinkResult[]
```

## Parameters

**`gl` `GlLinker`**

a WebGL2 context, or anything satisfying [`GlLinker`](https://typeshade.dev/api/gllinker/).

**`family` `VariantFamily<A>`**

the family to enumerate; every key in `family.keys` is attempted.

**`opts` optional `EmitOptions`**

emit options, applied to every variant equally. To check the production output, pass the same plugins the production emit uses, for example `{ plugins: obfuscate() }`.

## Return value

`readonly VariantLinkResult[]`

one result per key, in `family.keys` order.

## Description

A module type-checks as a whole, but the combination of axis values a host actually selects is only proven when a driver compiles and links it. This function enumerates the family, emits GLSL ES 3.00 for each variant, compiles the vertex and fragment shaders and links them into a program, and reports the outcome per key.

```ts
const gl = canvas.getContext('webgl2')!
const failed = linkVariants(gl, family).filter((r) => !r.ok)
expect(failed, failed.map((r) => `${r.key}: ${r.failedAt} ${r.log}`).join('\n')).toEqual([])
```

Every variant is attempted even after one fails, so the result lists every broken combination in one run.

GL objects are deleted as it goes: a family is a cartesian product, and a matrix with a few axes would otherwise leak hundreds of programs on a context that is usually shared with a live page.

## See also

- [`GlLinker`](https://typeshade.dev/api/gllinker/)

## Source

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