---
title: "TS8004 UNKNOWN_FN: an error code of the TypeShade compiler"
description: "TS8004 UNKNOWN_FN, an error code of the TypeShade compiler. A call to a function the file neither declares nor imports…"
url: https://typeshade.dev/reference/errors/ts8004/
language: en
---

# `TS8004`

Front-end code `UNKNOWN_FN`

A call to a function the file neither declares nor imports, or to a builtin the language removed because ECMAScript spells it, such as `arrayLength(xs)`, whose message names `xs.length` ([Rule 9.9](https://typeshade.dev/reference/rules/9-9/)).

The registry has no documentation comment for this constant, so the line above is written by this site from the messages the compiler raises it with.

The registry text and every compiler message on these pages are the compiler's own English.

## Example

example.shade.ts

```ts
"use typeshade"

@fragment
export function main(uv: location<0, vec2>): vec4 {
  return vec4(uv, brightness(uv), 1.)
}
```

Compiled at build time against the pinned compiler, this program gets:

**TS8004** error, line 5: Unknown function "brightness". Declare it in this file, or import it from another shader module.

## How to fix it

The same program, corrected. It compiles with no diagnostic.

example.shade.ts

```ts
"use typeshade"
import { brightness } from "./brightness.shade.ts"

@fragment
export function main(uv: location<0, vec2>): vec4 {
  return vec4(uv, brightness(uv), 1.)
}
```

It imports from another file of the same program, which `compile()` reads through its `readDocument` option:

brightness.shade.ts

```ts
"use typeshade"

export function brightness(uv: vec2): f32 {
  return (uv.x + uv.y) * 0.5
}
```

## The rules this enforces

**[Rule 2.1](https://typeshade.dev/reference/rules/2-1/) Test**

Every author-facing name must come from exactly one of three sources:

**[Rule 2.2](https://typeshade.dev/reference/rules/2-2/) Test**

A compiler-internal name (§2.1) must not be authorable.

**[Rule 7.7](https://typeshade.dev/reference/rules/7-7/) Test**

`discard` must be written as a bare statement, the identifier alone (`discard`), and may stand in a fragment entry and in a helper no vertex or compute entry can reach.

**[Rule 9.9](https://typeshade.dev/reference/rules/9-9/) Test**

A WGSL built-in function, an overload of one, or a §9.3 name must not be authorable when an ECMAScript spelling the compiler supports carries every case it accepts with the same meaning ([Rule 1.4](https://typeshade.dev/reference/rules/1-4/)).

## See also

- [Functions](https://typeshade.dev/guide/language/functions/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

Where the compiler raises this code at commit af54ddad5, one line per file:

- [`src/compiler/ts/lower/expression-call.ts:435`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/expression-call.ts#L435) (3 sites)
- [`src/compiler/ts/semantic.ts:616`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/semantic.ts#L616)
- [`src/compiler/ts/source-file.ts:476`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/source-file.ts#L476)
- [`src/core/coverage/glsl/common-functions.ts:101`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/coverage/glsl/common-functions.ts#L101)
- [`src/core/coverage/glsl/float-bits-and-packing.ts:10`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/coverage/glsl/float-bits-and-packing.ts#L10) (2 sites)
- [`src/core/coverage/glsl/geometric-and-matrix.ts:90`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/coverage/glsl/geometric-and-matrix.ts#L90) (3 sites)
- [`src/core/coverage/glsl/texture-lookups.ts:32`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/coverage/glsl/texture-lookups.ts#L32) (9 sites)
- [`src/core/coverage/wgsl/derivative-and-float-functions.ts:209`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/coverage/wgsl/derivative-and-float-functions.ts#L209)
- [`src/core/coverage/wgsl/functions-i32-to-normalize.ts:209`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/coverage/wgsl/functions-i32-to-normalize.ts#L209)
- [`src/core/coverage/wgsl/texture-query-and-load-functions.ts:116`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/coverage/wgsl/texture-query-and-load-functions.ts#L116)
- [`src/core/coverage/wgsl/texture-sample-functions.ts:31`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/coverage/wgsl/texture-sample-functions.ts#L31)
