---
title: "emitFunc(): function in Emit, TypeShade API reference"
description: "emitFunc, a function in Emit. Emit one FuncDecl as a WGSL function, exactly as given."
url: https://typeshade.dev/api/emitfunc/
language: en
---

# `emitFunc()`

Function in Emit

Emit one FuncDecl as a WGSL function, exactly as given.

`import { emitFunc } from 'typeshade'`

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

## Syntax

```ts
const emitFunc: (f: FuncDecl) => string
```

## Parameters

**`f` `FuncDecl`**

## Return value

`string`

## Description

Prefer [`emitFuncs`](https://typeshade.dev/api/emitfuncs/) for authored functions. This function skips every pass [`emitModule`](https://typeshade.dev/api/emitmodule/) runs before writing: [`autoVars`](https://typeshade.dev/api/autovars/), `match` lowering ([`lowerModule`](https://typeshade.dev/api/lowermodule/)), double-precision lowering ([`fp64Lower`](https://typeshade.dev/api/fp64lower/)) and the optimizer. A function that still contains a `match` expression or an `f64` type therefore throws, because those constructs exist only before lowering, and a function the optimizer would have simplified is written as authored. Use it only when the declaration needs none of those passes, such as a hand-written helper built from plain `f32` arithmetic.

Parenthesisation is always `'full'`. [`emitModule`](https://typeshade.dev/api/emitmodule/) passes its `parens` option down to the same speller, so a module emitted with `parens: 'minimal'` spells the same function with fewer parentheses. A function emitted here matches its text inside a module emitted with the default option, and may differ from its text inside a `'minimal'` one.

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | Writes WGSL for WebGPU. |
| GLSL ES 3.00 (WebGL2) | Does not apply | |
| CPU oracle | Does not apply | |

## See also

- [`FuncDecl`](https://typeshade.dev/api/funcdecl/)
- [`emitFuncs`](https://typeshade.dev/api/emitfuncs/)
- [`emitModule`](https://typeshade.dev/api/emitmodule/)
- [`autoVars`](https://typeshade.dev/api/autovars/)
- [`lowerModule`](https://typeshade.dev/api/lowermodule/)
- [`fp64Lower`](https://typeshade.dev/api/fp64lower/)

## Source

[`src/core/backends/wgsl.ts`, line 196](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/backends/wgsl.ts#L196), at commit af54ddad5
