---
title: "SwitchChain: class in Authoring, TypeShade API reference"
description: "SwitchChain, a class in Authoring. switch (scrut) { case n: …; default: … } as a chainable statement builder…"
url: https://typeshade.dev/api/switchchain/
language: en
---

# `SwitchChain`

Class in Authoring

switch (scrut) { case n: …; default: … } as a chainable statement builder, mirroring the If(…).elif(…).else(…) surface so integer dispatch reads the familiar imperative way: declare a Var(/api/var/) holding the default, then assign it inside the case arms.

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

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

## Syntax

```ts
class SwitchChain
```

## Description

Emits a real `switch` on both targets. `.case(n, body)` adds a case label; `.default(body?)` adds the optional default arm and ends the chain, pushing the statement.

## Examples

### Example

```ts
const radiusPx = Var(rawRadius)
Switch(sizeMode)
  .case(1, () => radiusPx.assign(rawRadius.div(viewport.z)))
  .case(2, () => radiusPx.assign(rawRadius.mul(2)))
  .default(() => {})
```

## Constructor

**`new SwitchChain(private readonly scrut: ReadonlyNode<'i32' | 'u32'>)`**

## Instance methods

**`case` `(value: number, body: () => void): SwitchChain`**

Add a `case value:` arm. Returns the chain.

**`default` `(body?: () => void): void`**

Add the optional `default:` arm and end the chain. The `switch` statement is pushed onto the innermost scope here, so a chain without `.default()` emits nothing.

## See also

- [`Var`](https://typeshade.dev/api/var/)
- [`Switch`](https://typeshade.dev/api/switch/)

## Source

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