---
title: "selectGuardedArm(): function in Variants, TypeShade API"
description: "selectGuardedArm, a function in Variants. Recover the arm a set of defined macros selects from an emitGuarded source."
url: https://typeshade.dev/api/selectguardedarm/
language: en
---

# `selectGuardedArm()`

Function in Variants

Recover the arm a set of defined macros selects from an emitGuarded source.

`import { selectGuardedArm } from 'typeshade'`

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

## Syntax

```ts
function selectGuardedArm(source: string, defined: Iterable<string>): string | undefined
```

## Parameters

**`source` `string`**

output of [`VariantFamily.emitGuarded`](https://typeshade.dev/api/variantfamily-interface/).

**`defined` `Iterable<string>`**

the macro names the host would have defined.

## Return value

`string | undefined`

the selected arm’s text, or `undefined` when no arm matches.

## Exceptions

**`Error`**

`Error` when a condition in `source` is not of the form the ladder generates.

## Description

Understands only the ladder shape `emitGuarded` generates: `#if`, `#elif` and `#endif` at column 0, with conditions built from `defined(X)` and `!defined(X)` joined by `&&`. Use it to assert, in a test or a build step, that the arm the host’s defines select equals the standalone variant from [`VariantFamily.emit`](https://typeshade.dev/api/variantfamily-interface/), without running a compiler.

## See also

- [`VariantFamily`](https://typeshade.dev/api/variantfamily-interface/)

## Source

[`src/core/variant-family.ts`, line 180](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/variant-family.ts#L180), at commit af54ddad5
