---
title: "add(): IR builder function in typeshade/core/ir, TypeShade"
description: "add, an IR builder function in typeshade/core/ir. a + b as a free function, the spelling for an expression whose left operand is a literal."
url: https://typeshade.dev/api/add/
language: en
---

# `add()`

Function in Builtins

a + b as a free function, the spelling for an expression whose left operand is a literal.

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

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

## Syntax

```ts
function add<E extends string, N extends number>(
  a: ReadonlyNode<E>,
  b: ReadonlyNode<`vec${N}<${E}>`>,
): Node<`vec${N}<${E}>`>;
function add<K extends string>(a: ReadonlyNode<K>, b: ArithArg<K>): Node<K>;
function add<K extends string>(a: number, b: ReadonlyNode<K>): Node<K>;
```

## Parameters

**`a` `ReadonlyNode<E>`**

**`b` ``ReadonlyNode<`vec${N}<${E}>`>``**

## Return value

``Node<`vec${N}<${E}>`>``

## Exceptions

**`TypeError`**

both operands are plain numbers.

## Description

`add(1, x)` is `f32(1).add(x)` without the wrapper, and emits the same `(1.0 + x)`.

Whichever operand is a node types the other: `add(1, u32node)` emits `1u`, the same typed lift `u32node.add(1)` performs. Two bare numbers are rejected — fold those on the host.

## Examples

### Example

```ts
import { fn, add, f32T } from 'typeshade/core/ir'

const shifted = fn('shifted', { x: f32T }, ({ x }) => add(0.5, x))
```

## See also

- [`ReadonlyNode`](https://typeshade.dev/api/readonlynode/)
- [`add`](https://typeshade.dev/api/add/)

## Source

[`src/core/ir/node.ts`, line 960](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L960), at commit af54ddad5
