---
title: "ReturnIf(): function in Authoring, TypeShade API reference"
description: "ReturnIf, a function in Authoring. Guard clause: if (cond) { return value; }, the explicit early return that reads as \"return value if cond\"."
url: https://typeshade.dev/api/returnif/
language: en
---

# `ReturnIf()`

Function in Authoring

Guard clause: if (cond) { return value; }, the explicit early return that reads as "return value if cond".

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

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

## Syntax

```ts
const ReturnIf: (cond: ReadonlyNode<"bool">, value?: ReadonlyNode) => void
```

## Parameters

**`cond` `ReadonlyNode<'bool'>`**

the guard condition.

**`value` optional `ReadonlyNode`**

the value to return; omit it for a bare `return;`.

## Return value

`void`

## Description

Guard clause: `if (cond) { return value; }`, the explicit early return that reads as “return value if cond”. It emits the same statements as `If(cond, () => Return(value))`. A native `return` inside an `If` body emits nothing, so an early return from a branch is written in one of these two forms.

## Examples

### Example

```ts
ReturnIf(winding.ne(0), f32(1).sub(min_dist))
Return(f32(1).add(min_dist))
```

## Source

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