---
title: "arrayOf(): function in Layout, TypeShade API reference"
description: "arrayOf, a function in Layout. Declare a fixed-length array field inside a uniformStruct field map."
url: https://typeshade.dev/api/arrayof/
language: en
---

# `arrayOf()`

Function in Layout

Declare a fixed-length array field inside a uniformStruct field map.

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

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

## Syntax

```ts
function arrayOf<H extends StructHandle>(element: H, count: number): HandleArray<H>;
function arrayOf<T extends ShaderType>(element: T, count: number): TypeArray<T>;
```

## Parameters

**`element` `H extends StructHandle`**

the element: a struct handle, or a shader type.

**`count` `number`**

the array length.

## Return value

`HandleArray<H>`

a [`HandleArray`](https://typeshade.dev/api/handlearray/) for a struct handle, a [`TypeArray`](https://typeshade.dev/api/typearray/) for a shader type.

## Description

The array is always `array<T, N>` with a declared `count`. A runtime-length `array<T>` is a top-level [`storageBuffer`](https://typeshade.dev/api/storagebuffer/) binding, which takes no count. Which overload applies is decided by the shape of `element`: a struct handle (from [`structDecl`](https://typeshade.dev/api/structdecl/) or [`ioStruct`](https://typeshade.dev/api/iostruct/), recognised by its `.of` method) returns a [`HandleArray`](https://typeshade.dev/api/handlearray/) whose field `.at(i)` gives the typed field proxy; a bare `ShaderType` returns a [`TypeArray`](https://typeshade.dev/api/typearray/) whose field `.at(i)` gives the element read directly.

## Examples

### Example

```ts
import { uniformStruct, arrayOf, vec4fT } from 'typeshade/core/ir'

const U = uniformStruct('Uniforms', { group: 0, binding: 0, as: 'u' }, {
  dash_array: arrayOf(vec4fT, 2),
})
const d0 = U.field.dash_array.at(0) // ReadonlyNode<'vec4<f32>'>
```

## See also

- [`uniformStruct`](https://typeshade.dev/api/uniformstruct/)
- [`storageBuffer`](https://typeshade.dev/api/storagebuffer/)
- [`structDecl`](https://typeshade.dev/api/structdecl/)
- [`ioStruct`](https://typeshade.dev/api/iostruct/)
- [`HandleArray`](https://typeshade.dev/api/handlearray/)
- [`TypeArray`](https://typeshade.dev/api/typearray/)

## Source

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