---
title: "structDecl(): function in Layout, TypeShade API reference"
description: "structDecl, a function in Layout. Declare a plain struct: one that never crosses a stage boundary."
url: https://typeshade.dev/api/structdecl/
language: en
---

# `structDecl()`

Function in Layout

Declare a plain struct: one that never crosses a stage boundary.

`import { structDecl } from 'typeshade/core/ir'`

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

## Syntax

```ts
function structDecl<F extends Record<string, ShaderType>, N extends string>(
  name: N,
  fields: F,
): PlainStruct<F, N>
```

## Parameters

**`name` `N extends string`**

the emitted struct name.

**`fields` `F extends Record<string, ShaderType>`**

the field map, each value a plain shader type.

## Return value

`PlainStruct<F, N>`

the [`PlainStruct`](https://typeshade.dev/api/plainstruct/) handle described above.

## Description

Declare a plain struct: one that never crosses a stage boundary. That is a storage-buffer element type, or a struct nested inside another struct. Fields are plain shader types with no `@location` or `@builtin` attribute, which is the whole difference from [`ioStruct`](https://typeshade.dev/api/iostruct/).

The returned handle carries:

- `.decl` for `module({ structs })`, or pass the handle in `uses`.
- `.type` for the struct’s shader type, which is what a parameter, a nested field or a [`storageBuffer`](https://typeshade.dev/api/storagebuffer/) element takes.
- `.of(node).field` for typed field reads off a value you hold as a raw node, and `.get(node, 'field')` for the positional spelling of the same read, which suits a call site that reads many fields through one shorthand.
- `.var(name)` for a mutable `var` of the struct, and `.construct({ ... })` for the one-expression build, exactly as [`ioStruct`](https://typeshade.dev/api/iostruct/) has them.

As a storage-buffer element type it is the argument [`storageBuffer`](https://typeshade.dev/api/storagebuffer/) takes, and `buf.at(i)` then returns this struct’s field proxy directly, with no `.of` step.

## Examples

### Example

```ts
import { structDecl, storageBuffer, u32T, vec2fT } from 'typeshade/core/ir'

const ShapeSegment = structDecl('ShapeSegment', { kind: u32T, p0: vec2fT, p1: vec2fT })
const segments = storageBuffer('segments', ShapeSegment, { group: 0, binding: 9, access: 'read' })

segments.at(i).p0 // Node<'vec2<f32>'>
ShapeSegment.get(someNode, 'kind') // the same read, positionally
```

## See also

- [`ioStruct`](https://typeshade.dev/api/iostruct/)
- [`storageBuffer`](https://typeshade.dev/api/storagebuffer/)
- [`PlainStruct`](https://typeshade.dev/api/plainstruct/)

## Source

[`src/core/sot.ts`, line 559](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/sot.ts#L559), at commit af54ddad5
