---
title: "Authoring, a category in the TypeShade API reference"
description: "Authoring in the TypeShade API reference. The builder a shader is written with: modules, functions, variables and control flow."
url: https://typeshade.dev/api/authoring/
language: en
---

# Authoring

48 members

The builder a shader is written with: modules, functions, variables and control flow.

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

**[`Break`](https://typeshade.dev/api/break/) Function**

Push a break; onto the innermost scope, exiting the nearest enclosing Loop outright, under the same nesting rule as Continue: an If nested inside the loop is not itself a break boundary.

**[`Builder`](https://typeshade.dev/api/builder/) Class**

The statement collector every fn() body writes into.

**[`Call`](https://typeshade.dev/api/call/) Function**

Push a call as a statement onto the innermost scope, kept for its effect and nothing else.

**[`compile`](https://typeshade.dev/api/compile/) Function**

Compile TypeShade TypeScript source into the module and generated shader outputs.

**[`CompileOptions`](https://typeshade.dev/api/compileoptions/) Interface**

How one compile() call is set up.

**[`CompileResult`](https://typeshade.dev/api/compileresult/) Interface**

What compile() returns.

**[`compileTsSource`](https://typeshade.dev/api/compiletssource/) Function**

Compile a TypeScript source string through the TypeShade authoring pipeline.

**[`CompileTsSourceOptions`](https://typeshade.dev/api/compiletssourceoptions/) Interface**

Options controlling compilation of a TypeShade TypeScript source string.

**[`CompileTsSourceResult`](https://typeshade.dev/api/compiletssourceresult/) Interface**

The result of compiling a TypeShade TypeScript source string, including IR and optional WGSL.

**[`condExpr`](https://typeshade.dev/api/condexpr/) Function**

N-arm value dispatch on conditions, the first true condition winning: condExpr(\[\[c0, () => e0\], \[c1, () => e1\]\], () => eN).

**[`constExpr`](https://typeshade.dev/api/constexpr/) Function**

Author a module-level constant from an IR value expression: the form for a constant that is not a plain scalar.

**[`ConstExprDecl`](https://typeshade.dev/api/constexprdecl/) Interface**

What constExpr returns: the ConstDecl itself, so it drops straight into module, carrying node, the typed reference to read the constant through at call sites.

**[`Continue`](https://typeshade.dev/api/continue/) Function**

Push a continue; onto the innermost scope, skipping to the next iteration of the nearest enclosing loop.

**[`Discard`](https://typeshade.dev/api/discard/) Function**

Push a discard; onto the innermost scope.

**[`externFn`](https://typeshade.dev/api/externfn/) Function**

Forward-declare a callable whose real definition (fn(...)) is authored somewhere else, or built later than the caller's own module-load time (see ExternFn).

**[`ExternFn`](https://typeshade.dev/api/externfn-type/) Type**

A typed call-only handle for a function whose definition is provided elsewhere: the forward-declaration counterpart to fn().

**[`externVar`](https://typeshade.dev/api/externvar/) Function**

Declare a host-provided global: the variable counterpart of externFn.

**[`ExternVarHandle`](https://typeshade.dev/api/externvarhandle/) Interface**

The pair externVar returns: the read node, and the declaration to hand module().

**[`findUseTypeshadeDirective`](https://typeshade.dev/api/findusetypeshadedirective/) Function**

Scan the top-level statements of a SourceFile and return the first "use typeshade"; directive, or undefined if none is present.

**[`fn`](https://typeshade.dev/api/fn/) Function**

Author a function. One call covers a plain helper and a `@vertex`, `@fragment` or `@compute` entry point.

**[`FnHandle`](https://typeshade.dev/api/fnhandle/) Type**

The type fn() returns: a typed, callable handle that is also a FuncDecl.

**[`FnParamSpec`](https://typeshade.dev/api/fnparamspec/) Type**

The parameter record fn() accepts.

**[`hasUseTypeshadeDirective`](https://typeshade.dev/api/hasusetypeshadedirective/) Function**

True when the SourceFile contains at least one top-level "use typeshade".

**[`If`](https://typeshade.dev/api/if/) Function**

Author if (cond) { body } over the innermost active scope.

**[`IfChain`](https://typeshade.dev/api/ifchain/) Class**

The chain object Builder.if and If(/api/if/) return, so .elif(...) and .else(...) read top to bottom in authored order.

**[`ifExpr`](https://typeshade.dev/api/ifexpr/) Function**

Two-arm value dispatch on a condition: ifExpr(cond, () => a, () => b).

**[`isTypeshadeSource`](https://typeshade.dev/api/istypeshadesource/) Function**

Return whether a TypeScript source string opts into TypeShade with the "use typeshade" directive.

**[`isUseTypeshadeDirective`](https://typeshade.dev/api/isusetypeshadedirective/) Function**

Returns true when node is a top-level "use typeshade"; statement.

**[`Let`](https://typeshade.dev/api/let/) Function**

Bind a value to an immutable local, emitting let name = expr; into the innermost active scope.

**[`Loop`](https://typeshade.dev/api/loop/) Function**

Author a C-style for loop over the innermost active scope.

**[`matchEnum`](https://typeshade.dev/api/matchenum/) Function**

Exhaustive integer dispatch over an enumU32: matchEnum(kind, Kind, { Line: () => …, Fill: () => …, … }).

**[`matchExpr`](https://typeshade.dev/api/matchexpr/) Function**

A typed multi-arm dispatch over a scalar scrutinee, the expression form of switch (scrutinee) { case v0: r0; …; default: dflt }.

**[`module`](https://typeshade.dev/api/module/) Function**

Assemble a module from its declarations.

**[`ModuleParts`](https://typeshade.dev/api/moduleparts/) Interface**

The input shape module accepts: a Partial<ModuleDecl> whose funcs also takes a key-named record as an alternative to the array, and whose uses derives structs, bindings and consts from declarator handles.

**[`overrideConst`](https://typeshade.dev/api/overrideconst/) Function**

Declare a pipeline specialization constant: one value that is fixed when a pipeline is created, later than module build and earlier than the draw.

**[`OverrideHandle`](https://typeshade.dev/api/overridehandle/) Interface**

The pair overrideConst returns for a pipeline specialization constant: .node reads the value, opaque to the optimizer, in any expression or branch condition, and .decl goes into module.

**[`ParamSpec`](https://typeshade.dev/api/paramspec/) Type**

The parameter record externFn takes: a plain map from parameter name to ShaderType, in declaration order.

**[`rawStmt`](https://typeshade.dev/api/rawstmt/) Function**

Author a raw statement, the escape hatch that splices verbatim text into a function body.

**[`reduce`](https://typeshade.dev/api/reduce/) Function**

Fold a value over a C-style loop: the value-returning spelling of the var acc = init; for (...) { acc = f(acc, i) } accumulator.

**[`Return`](https://typeshade.dev/api/return/) Function**

Push an explicit return value; onto the innermost scope.

**[`ReturnIf`](https://typeshade.dev/api/returnif/) Function**

Guard clause: if (cond) { return value; }, the explicit early return that reads as "return value if cond".

**[`Switch`](https://typeshade.dev/api/switch/) Function**

Open a switch (scrut) chain: Switch(scrut).case(n, body)….default(body).

**[`SwitchChain`](https://typeshade.dev/api/switchchain/) Class**

switch (scrut) { case n: …; default: … } as a chainable statement builder, mirroring the If(…).elif(…).else(…) surface so integer dispatch reads the familiar imperative way: declare a Var(/api/var/) holding the default, then assign it inside the case arms.

**[`TsCompilerDiagnostic`](https://typeshade.dev/api/tscompilerdiagnostic/) Interface**

A source diagnostic produced while TypeShade analyzes or compiles TypeScript shader code.

**[`USE_TYPESHADE`](https://typeshade.dev/api/usetypeshade/) Constant**

The exact string the directive must carry.

**[`UsesHandle`](https://typeshade.dev/api/useshandle/) Type**

A declarator handle accepted by module({ uses }): anything that carries its own declaration or binding.

**[`Var`](https://typeshade.dev/api/var/) Function**

Declare a mutable local and return the node that reads and writes it.

**[`when`](https://typeshade.dev/api/when/) Function**

Dispatch a value on a condition, returning the value instead of mutating a var.
