Skip to main content
You can call functions from existing TypeScript and JavaScript files inside your Forst program. This lets you move backend code to Forst step by step. Working JavaScript code stays in place while new code compiles to Go. To call Forst over HTTP instead, see Call Forst over HTTP.
The postfix js marker tells Forst that this path points to a JavaScript module. The compiler checks the function name, arguments, and return value. Every call returns a Result, so ensure result is Ok() handles failures before you use the value. At runtime, the compiled app starts a local bridge process when it first runs a JS import call. If your program does not use a JS import, the compiled binary does not need JavaScript.

Set up JavaScript imports

Install @forst/runtime in your project root.
Enable the bridge in ftconfig.json.
Forst only loads modules opted in with the postfix js marker. Plain imports never start the JS bridge.

Import a module

Use the file name as the local name, or choose an alias. You can also group imports together.
Each import exposes the module namespace. For example, payment.create calls the create export. Your TypeScript files need no special Forst annotations.

Alias reserved names

When the file or package name matches a Forst or Go keyword, Forst reports an error and asks for an alias.
Scoped npm packages like @effect/platform default to the last path segment (platform) when that name is valid.

Call synchronous functions

Synchronous JavaScript functions look like normal calls in Forst. The result is wrapped in Result(T, Error) because the local IPC call can still fail. Use ensure … is Ok() or if … is Err() before reading the returned value.

Call asynchronous functions

You can call an async JavaScript function from normal Forst code. The bridge waits for the Promise to settle and returns its value. You do not add async or await to your Forst code.

Separate system errors from return values

Two different things can fail during a call. The bridge runtime itself can fail, or your JavaScript function can return an error value. If an async JavaScript function resolves to a tagged union, Forst maps that union as T. The outer return type remains Result(T, Error).

Read streams and generators

JavaScript generator functions appear as Seq[T] in Forst. Check that the generator opened successfully, then use a for range loop to read items.
Both sync and async generators use Seq[T]. The bridge pulls items in batches to cut IPC round trips.

Next steps