---
title: "externRef(): IR builder function in typeshade/core/ir"
description: "externRef, an IR builder function in typeshade/core/ir. A read of a global the host provides…"
url: https://typeshade.dev/api/externref/
language: en
---

# `externRef()`

Function in Values

A read of a global the host provides, the read side of an externVar(...) declaration and the variable counterpart of an externFn call.

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

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

## Syntax

```ts
function externRef<T extends ShaderType>(name: string, type: T): ReadonlyNode<KeyOf<T>>
```

## Parameters

**`name` `string`**

**`type` `T extends ShaderType`**

## Return value

`ReadonlyNode<KeyOf<T>>`

## Description

A read of a global the host provides, the read side of an `externVar(...)` declaration and the variable counterpart of an `externFn` call. It is read-only: the host owns the value. The optimizer treats it as opaque, like [`overrideRef`](https://typeshade.dev/api/overrideref/): the value is unknown when the module is built, so no folding or dead-branch pass may collapse a branch it guards. Authoring code reads through the handle `externVar` returns; this is the primitive behind that handle.

## See also

- [`overrideRef`](https://typeshade.dev/api/overrideref/)

## Source

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