---
title: "validateVariantsWgsl(): function in Variants, TypeShade API"
description: "validateVariantsWgsl, a function in Variants. Validate every variant of a family through a real WGSL compiler."
url: https://typeshade.dev/api/validatevariantswgsl/
language: en
---

# `validateVariantsWgsl()`

Function in Variants

Validate every variant of a family through a real WGSL compiler.

`import { validateVariantsWgsl } from 'typeshade'`

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

## Syntax

```ts
async function validateVariantsWgsl<A extends Record<string, readonly unknown[]>>(
  device: WgslValidator,
  family: VariantFamily<A>,
  opts?: EmitOptions,
): Promise<readonly VariantWgslResult[]>
```

## Parameters

**`device` `WgslValidator`**

a `GPUDevice`, or anything satisfying [`WgslValidator`](https://typeshade.dev/api/wgslvalidator/).

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

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

**`opts` optional `EmitOptions`**

emit options, applied to every variant equally.

## Return value

`Promise<readonly VariantWgslResult[]>`

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

## Description

The WGSL counterpart of [`linkVariants`](https://typeshade.dev/api/linkvariants/): the same enumeration, the same rule that every variant is attempted even after one fails, and the same per-key result shape. One WGSL module carries both entry points, so `createShaderModule()` followed by `getCompilationInfo()` is the whole check. `getCompilationInfo()` is asynchronous, which is why this function returns a promise while [`linkVariants`](https://typeshade.dev/api/linkvariants/) does not.

```ts
const device = await (await navigator.gpu.requestAdapter())!.requestDevice()
const failed = (await validateVariantsWgsl(device, family)).filter((r) => !r.ok)
expect(failed, failed.map((r) => `${r.key}: ${r.errors?.join('; ')}`).join('\n')).toEqual([])
```

`createShaderModule()` does not throw on invalid WGSL; the errors arrive through `getCompilationInfo()`. This function reads those messages, so a shader that compiles without throwing but reports errors is still a failure.

## See also

- [`linkVariants`](https://typeshade.dev/api/linkvariants/)
- [`WgslValidator`](https://typeshade.dev/api/wgslvalidator/)

## Source

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