---
title: "Switch(): function in Authoring, TypeShade API reference"
description: "Switch, a function in Authoring. Open a switch (scrut) chain: Switch(scrut).case(n, body)….default(body)."
url: https://typeshade.dev/api/switch/
language: en
---

# `Switch()`

Function in Authoring

Open a switch (scrut) chain: Switch(scrut).case(n, body)….default(body).

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

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

## Syntax

```ts
function Switch(scrut: ReadonlyNode<'i32' | 'u32'>): SwitchChain
```

## Parameters

**`scrut` `ReadonlyNode<'i32' | 'u32'>`**

the integer value dispatched on.

## Return value

`SwitchChain`

the chain, for `.case` and `.default`.

## Description

The scrutinee is a read position, so a read-only node is accepted, and it must be `i32` or `u32`: WGSL and GLSL ES 3.00 both type `switch` over integers only.

## See also

- [`SwitchChain`](https://typeshade.dev/api/switchchain/)
- [`when`](https://typeshade.dev/api/when/)

## Source

[`src/core/ir/builder.ts`, line 1840](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/builder.ts#L1840), at commit af54ddad5
