---
title: "ShaderType: type in Types, TypeShade API reference"
description: "ShaderType, a type in Types. The runtime type descriptor for every value the DSL can represent: a plain, comparable discriminated union…"
url: https://typeshade.dev/api/shadertype/
language: en
---

# `ShaderType`

Type in Types

The runtime type descriptor for every value the DSL can represent: a plain, comparable discriminated union, so a switch (t.kind) over it is exhaustively checked by tsc at every site that must decide what to do with a shape (typeKey, wgslLayout, both backends' emit walkers).

`import type { ShaderType } from 'typeshade'`
`import type { ShaderType } from 'typeshade/core/ir'`

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

## Syntax

```ts
type ShaderType =
  | { readonly kind: 'scalar'; readonly scalar: Scalar }
  | { readonly kind: 'f64' }
  | { readonly kind: 'vec64'; readonly n: 2 | 3 | 4 }
  | { readonly kind: 'vec'; readonly n: 2 | 3 | 4; readonly elem: 'f32' | 'i32' | 'u32' | 'bool' }
  | {
      readonly kind: 'mat';
      readonly cols: 2 | 3 | 4;
      readonly rows: 2 | 3 | 4;
      readonly elem: 'f32' | 'f64';
    }
  | { readonly kind: 'struct'; readonly name: string }
  | {
      readonly kind: 'array';
      readonly elem: ShaderType;
      readonly size?: number;
      /** Pipeline override used as this array's symbolic outer extent. `size` remains the
       *  positive default extent for reflection and the CPU oracle. */
      readonly sizeOverride?: string;
    }
  | { readonly kind: 'atomic'; readonly elem: 'u32' | 'i32' }
  | {
      readonly kind: 'texture';
      readonly dim: '2d' | '2d-array' | 'cube' | '3d' | '1d' | 'cube-array' | '2d-ms';
      readonly elem: TextureElem;
    }
  | {
      readonly kind: 'storage-texture';
      readonly dim: '2d' | '2d-array';
      readonly format: StorageTextureFormat;
      readonly access: StorageTextureAccess;
    }
  | {
      readonly kind: 'depth-texture';
      readonly dim: '2d' | '2d-array' | 'cube' | 'cube-array' | '2d-ms';
    }
  | { readonly kind: 'sampler' }
  | { readonly kind: 'sampler-comparison' }
  | {
      readonly kind: 'collection';
      readonly key: 'u32' | 'i32' | 'f32';
      readonly value?: ShaderType;
    }
  | { readonly kind: 'void' };
```

## Description

Do not build one as an object literal. Use the named constants (`f32T`, `vec3fT`, …) or the [`structT`](https://typeshade.dev/api/structt/) and [`arrayT`](https://typeshade.dev/api/arrayt/) constructors, which keep the `as const satisfies ShaderType` narrowing that [`KeyOf`](https://typeshade.dev/api/keyof/) depends on to resolve a precise string key instead of `string`. [`typeKey`](https://typeshade.dev/api/typekey/) turns any `ShaderType` into that same key at runtime; `KeyOf<T>` is its type-level mirror, which lets [`Node`](https://typeshade.dev/api/node/) carry the key as a compile-time phantom so a type mismatch is a `tsc` error instead of an [`SD0002`](https://typeshade.dev/reference/errors/sd0002/) thrown when the authoring code runs.

## See also

- [`typeKey`](https://typeshade.dev/api/typekey/)
- [`wgslLayout`](https://typeshade.dev/api/wgsllayout/)
- [`structT`](https://typeshade.dev/api/structt/)
- [`arrayT`](https://typeshade.dev/api/arrayt/)
- [`KeyOf`](https://typeshade.dev/api/keyof/)
- [`Node`](https://typeshade.dev/api/node/)

## Source

[`src/core/ir/types/shader-type.ts`, line 27](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/types/shader-type.ts#L27), at commit af54ddad5
