---
title: "ConstDecl: interface in IR, TypeShade API reference"
description: "ConstDecl, an interface in IR. A ModuleDecl.consts entry: a module-scope constant."
url: https://typeshade.dev/api/constdecl-interface/
language: en
---

# `ConstDecl`

Interface in IR

A ModuleDecl.consts entry: a module-scope constant.

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

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

## Syntax

```ts
interface ConstDecl {
  readonly name: string;
  readonly type: ShaderType;
  readonly wgslValue: number;
  readonly cpuValue: number;
  readonly valueExpr?: Expr;
}
```

## Description

For a scalar, write a plain object literal with one value per precision, for example `{ name: 'PI', type: f32T, wgslValue: 3.14159265, cpuValue: Math.PI }`: the WGSL and GLSL backends emit `wgslValue`, and the CPU backend, which runs the module in double precision, uses `cpuValue`. For a vector, array or struct constant use [`constExpr`](https://typeshade.dev/api/constexpr/), which fills `valueExpr` instead. When both forms are present, `valueExpr` wins.

## Instance properties

**`name` read only `string`**

**`type` read only `ShaderType`**

**`wgslValue` read only `number`**

Scalar value emitted by the WGSL/GLSL backends (the truncated shader constant). Used when `valueExpr` is absent; ignored otherwise.

**`cpuValue` read only `number`**

Scalar value used by the CPU backend, at full double precision. Used when `valueExpr` is absent; ignored otherwise.

**`valueExpr` optional read only `Expr`**

Optional constant value as an IR literal expression, for example a `vec4<f32>(…)` colour, an `array<vec4<f32>, N>(…)` palette, or a struct literal. When present it replaces `wgslValue` and `cpuValue` on every backend: WGSL and GLSL emit it and the CPU backend evaluates it. It must be a constant-foldable literal expression (`lit`, `construct`, `unop` or `binop` over those, or a `constref` to an earlier constant); it may not read a binding, a parameter, or a runtime input. Ordinary `f32` scalars keep using the `wgslValue`/`cpuValue` pair.

## See also

- [`constExpr`](https://typeshade.dev/api/constexpr/)

## Source

[`src/core/ir/nodes.ts`, line 352](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/nodes.ts#L352), at commit af54ddad5
