---
title: "mix(): IR builder function in typeshade/core/ir, TypeShade"
description: "mix, an IR builder function in typeshade/core/ir. mix(a, b, t): linear interpolation a + t·(b − a), component-wise, keyed by a."
url: https://typeshade.dev/api/mix/
language: en
---

# `mix()`

Function in Builtins

`mix(a, b, t)`: linear interpolation a + t·(b − a), component-wise, keyed by a.

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

This export returns an IR node. A `"use typeshade"` file calls the builtin itself: [`mix()`](https://typeshade.dev/reference/functions/mix/)

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

## Syntax

```ts
function mix<K extends FloatKey | Float64Key>(
  a: ReadonlyNode<K>,
  b: NoInfer<ArithArg<K>>,
  t: ReadonlyNode<'f32'> | number,
): Node<K>;
function mix(
  a: number,
  b: ReadonlyNode<'f32'> | number,
  t: ReadonlyNode<'f32'> | number,
): Node<'f32'>;
```

## Parameters

**`a` `ReadonlyNode<K>`**

**`b` `NoInfer<ArithArg<K>>`**

**`t` `ReadonlyNode<'f32'> | number`**

## Return value

`Node<K>`

## Description

A `t` outside `[0, 1]` extrapolates; pass `t` through [`clamp`](https://typeshade.dev/api/clamp/) or [`smoothstep`](https://typeshade.dev/api/smoothstep/) when the result must stay within the `a..b` range.

## Examples

### Example

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

const blend = fn('blend', { t: f32T }, ({ t }) => mix(vec3(0, 0, 0), vec3(1, 1, 1), t))
```

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `mix(a, b, t)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| GLSL ES 3.00 (WebGL2) | Supported | `mix(a, b, t)`. Over `f64` operands the fp64 pass rewrites it into its `df64` helper. |
| CPU oracle | Supported | Evaluated in `f64` by the oracle. |

## In the guide

- [Values and mutation](https://typeshade.dev/guide/internals/values-and-mutation/)
- [fp64](https://typeshade.dev/guide/internals/fp64/)

## See also

- [`mix()`](https://typeshade.dev/reference/functions/mix/)
- [`clamp`](https://typeshade.dev/api/clamp/)
- [`smoothstep`](https://typeshade.dev/api/smoothstep/)

## Source

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