---
title: "ioStruct(): function in Layout, TypeShade API reference"
description: "ioStruct, a function in Layout. Declare a struct that crosses a stage boundary, a vertex output, a fragment input, a compute IO record, from one field map."
url: https://typeshade.dev/api/iostruct/
language: en
---

# `ioStruct()`

Function in Layout

Declare a struct that crosses a stage boundary, a vertex output, a fragment input, a compute IO record, from one field map.

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

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

## Syntax

```ts
function ioStruct<F extends Record<string, FieldSpec>, N extends string>(
  name: N,
  fields: F,
): IoStruct<F, N>
```

## Parameters

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

the emitted struct name.

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

the field map, each value a `builtin(...)` or `location(...)` spec.

## Return value

`IoStruct<F, N>`

the [`IoStruct`](https://typeshade.dev/api/iostruct-interface/) handle described above.

## Description

Every field is a [`builtin`](https://typeshade.dev/api/builtin/) or [`location`](https://typeshade.dev/api/location/) spec, so the attributes live with the field they belong to and the struct is declared once.

The returned handle carries everything the rest of the module needs:

- `.type` is the struct’s [`ShaderType`](https://typeshade.dev/api/shadertype/). Use it as a parameter type, `{ vo: VsOut.type }`, or pass the handle itself in an [`fn`](https://typeshade.dev/api/fn/) param record and the body receives the typed field proxy.
- `.decl` is the `StructDecl` for `module({ structs })`, or pass the handle in `uses`.
- `.of(node)` reads fields off a value of this struct: `VsOut.of(p.vo).uv` is typed, and a misspelled field is a tsc error. The view follows its base, so a read-only base yields read-only fields.
- `.var(name)` declares a `var` of the struct and returns assignable fields: `o.pos.assign(...)`. The proxy reads as the raw node in value positions, and `.$` is that raw struct value where an explicit one is wanted.
- `.construct({ ... })` builds the value in one expression, keyed by field name, with a missing or extra field a tsc error. It is the form to prefer when nothing needs mutating.

## Examples

### Example

```ts
import { ioStruct, builtin, location, vec4fT, vec2fT, f32T } from 'typeshade/core/ir'

const VsOut = ioStruct('VsOut', {
  pos: builtin('position', vec4fT),
  uv: location(0, vec2fT),
  vis: location(1, f32T),
})

const pin = VsOut.of(p.vo) // pin.uv, pin.vis are typed reads
return VsOut.construct({ pos: clip, uv, vis })
```

## See also

- [`builtin`](https://typeshade.dev/api/builtin/)
- [`location`](https://typeshade.dev/api/location/)
- [`ShaderType`](https://typeshade.dev/api/shadertype/)
- [`fn`](https://typeshade.dev/api/fn/)
- [`IoStruct`](https://typeshade.dev/api/iostruct-interface/)
- [`structDecl`](https://typeshade.dev/api/structdecl/)
- [`uniformStruct`](https://typeshade.dev/api/uniformstruct/)

## Source

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