Skip to content

Overview ​

Weft is one language for a whole app: its screens, its logic and its server. It reads like TypeScript, and its values behave like Rust's or Swift's: every value is a copy, and nothing changes your data unless you hand it over with &.

lib/hello.weft
weft
import { assertEq } from "std/testing"

/// The greeting for a name, or for a stranger.
export fn greet(name: string?): string {
  let n = name else { return "Hello, stranger" }
  return `Hello, ${n}`
}

test "greets by name" {
  assertEq(greet("Ada"), "Hello, Ada")
  assertEq(greet(null), "Hello, stranger")
}

New here? Get started installs weft and makes an app in a minute. The guide then goes in order:

Each page shows a concept in code first, then says what it does. The guide explains; the reference defines: it is the specification itself, and it wins where the two differ.

The examples ​

Every Weft example on this site is a whole file, and the compiler checks it when the site is built: if one stops compiling, the site doesn't deploy. A caption above an example can say more.

rejected by the compiler (E2001)
weft
export fn label(count: number): string {
  return "Items: " + count
}
  • A file name (lib/hello.weft) means the file's place in its project matters, usually for imports.
  • rejected by the compiler marks an example that shows a mistake on purpose, like the one above: the compiler must reject it with the code shown (weft codes lists them all).
  • uses … not built yet marks an example that needs a part of Weft that doesn't exist yet. Everything else in it is checked.

The tools ​

commandwhat it does
weft new <dir>makes an app from the template (Get started)
weft dev <project>serves an app at localhost:3000 and reloads on every change; --window opens it in the desktop app
weft run <file or project>runs a program's top level (and its main), or serves an app
weft check <files or dirs>type-checks and reports diagnostics (--short, --json)
weft test <project>runs the project's test blocks on the VM's test host
weft fmt <files or dirs>formats files in place (--check only reports)
weft component <name>…copies registry components into components/ui/ (UI components)
weft build --target js <project>compiles a project to JavaScript modules and static CSS
weft render --html <project> <path>prints a page as the server renders it
weft db migrate|apply|push <project>writes and runs std/db migrations (Data)
weft migrate <files>rewrites today's markup-kit files (a JavaScript subset) to Weft
weft codeslists every diagnostic code with what it means

A file is checked inside its project: the nearest folder above it with a weft.toml, or else its own folder.

Coming from TypeScript ​

Weft reads like TypeScript on purpose. These are the differences you will meet first:

TypeScriptWeft
undefined and nullonly null; T? means T | null
=====, which compares structurally ([1, 2] == [1, 2] is true)
"a" + 1 is "a1"a type error; write `a${1}`
if (list.length) …a type error; conditions are booleans: if list.length > 0 { … }, no parentheses, always braces
const and letlet (nothing in it can change) and let mut
function f() {}fn f() {}
for (let i = 0; i < n; i++)for i of 0..n
switchmatch, which must cover every case
throw, try { … } catchfail e; try f() passes an error on, let v, err = try f() handles it (Errors)
finallydefer
Math.floor, JSON.parse, console.logimported: floor from std/math, parse from std/json, log from std/log
objects are shared by referenceevery value is a copy; & hands a place to a function that changes it
classes, this, newrecords and functions; Map<string, number>() without new
enumvariants: type Shape = Circle { r: number } | Empty
any, unknownjson for dynamic data, narrowed with is and as

Weft is in development. The reference is the spec as it stands today.