Appearance
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:
- The language: basics, types, values and borrows, functions and closures, modules and projects, tests and limits.
- Apps: components and reactivity, the app framework, UI components, the server, data, user-editable apps, the desktop app and using Weft with AI agents.
- Recipes: whole tasks, each a small project: a form, a live list, signing in, an endpoint, a window, pages users write.
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 codeslists 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
| command | what 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 codes | lists 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:
| TypeScript | Weft |
|---|---|
undefined and null | only 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 let | let (nothing in it can change) and let mut |
function f() {} | fn f() {} |
for (let i = 0; i < n; i++) | for i of 0..n |
switch | match, which must cover every case |
throw, try { … } catch | fail e; try f() passes an error on, let v, err = try f() handles it (Errors) |
finally | defer |
Math.floor, JSON.parse, console.log | imported: floor from std/math, parse from std/json, log from std/log |
| objects are shared by reference | every value is a copy; & hands a place to a function that changes it |
classes, this, new | records and functions; Map<string, number>() without new |
enum | variants: type Shape = Circle { r: number } | Empty |
any, unknown | json for dynamic data, narrowed with is and as |