---
title: "PlainStruct: interface in Layout, TypeShade API reference"
description: "PlainStruct, an interface in Layout. The handle structDecl returns: a struct declared for something other than a stage's IO boundary…"
url: https://typeshade.dev/api/plainstruct/
language: en
---

# `PlainStruct`

Interface in Layout

The handle structDecl returns: a struct declared for something other than a stage's IO boundary, such as a storage-buffer element type (paired with storageBuffer) or a struct nested inside another struct.

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

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

## Syntax

```ts
interface PlainStruct<F extends Record<string, ShaderType>, N extends string = string> {
  readonly decl: StructDecl;
  readonly type: { readonly kind: 'struct'; readonly name: N };
  of(node: Node): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; };
  of(node: ReadonlyNode): { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; };
  get<K extends keyof F & string>(node: ReadonlyNode, field: K): ReadonlyNode<KeyOf<F[K]>>;
  var(name?: string): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; };
  construct(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> }): Node<`struct:${N}`>;
}
```

## Description

Fields are plain `ShaderType`s with no `@location` or `@builtin` attribute; [`IoStruct`](https://typeshade.dev/api/iostruct-interface/) is the twin that carries those. It has the same shape as `IoStruct` (`.decl`, `.type`, `.of`, `.var`, `.construct`) plus a positional `.get(node, field)` reader.

## Instance properties

**`decl` read only `StructDecl`**

The struct declaration, for `module({ structs })`.

**`type` read only `{ readonly kind: 'struct'; readonly name: N }`**

The struct’s `ShaderType`, carrying the name as a literal so every value built from this handle has the exact `struct:${N}` key [`typeKey`](https://typeshade.dev/api/typekey/) produces.

## Instance methods

**`of` ``(node: Node): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }``**

Typed field access on a struct value you hold as a raw node: `Seg.of(someNode).p0`. A storage-buffer element does not need it, because `buf.at(i)` already returns this proxy. The view’s write capability follows the base: a mutable base gives `Node` fields, a read-only base gives `ReadonlyNode` fields. `.$` is the raw struct value, which can be passed on to a function that takes the struct.

**`of` ``(node: ReadonlyNode): { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }``**

**`get` `<K extends keyof F & string>(node: ReadonlyNode, field: K): ReadonlyNode<KeyOf<F[K]>>`**

Positional field access: `Seg.get(node, 'p0')` is the same read as `Seg.of(node).p0`, with a wrong field name a `tsc` error. It suits a call site that reads many fields through one shorthand (`const g = Seg.get`). It is a read accessor and returns `ReadonlyNode`.

**`var` ``(name?: string): { readonly [K in keyof F]: Node<KeyOf<F[K]>> } & { readonly $: ReadonlyNode<`struct:${N}`>; }``**

Declare a `var` of this struct and return its typed, mutable field proxy, as `IoStruct.var` does.

**`construct` ``(values: { readonly [K in keyof F]: ReadonlyNode<KeyOf<F[K]>> }): Node<`struct:${N}`>``**

Build a value of this struct in one expression, keyed by field name and placed in declaration order, as `IoStruct.construct` does.

## See also

- [`structDecl`](https://typeshade.dev/api/structdecl/)
- [`storageBuffer`](https://typeshade.dev/api/storagebuffer/)
- [`IoStruct`](https://typeshade.dev/api/iostruct-interface/)
- [`typeKey`](https://typeshade.dev/api/typekey/)

## Source

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