Modules
Modules are ES modules: import and export as in JS. Imports of .rk modules are checked: the compiler reads their exports and knows their types. As the board grows, its task definition, collection operations and entry point can live in separate .rk modules; checked imports carry exported types between them.
Types of npm packages, .ts files and Node modules (node:fs) come from TypeScript declarations: readFileSync(path, "utf8") is a string, and request.url of an IncomingMessage is a ?string. A module without declarations is any. The playground works without the TypeScript compiler, so such imports are any here.
rook build compiles a file together with every .rk module it imports and replaces .rk with .js in the paths. Next to each .js it writes a .d.ts, so TypeScript code can import the module with types, and a source map, .js.map, so that stack traces and debuggers show the lines of the .rk file; rook run shows them too.
A module that gathers the API of a folder passes on names of others: export { Rows } from "./rows.rk" and export * from "./rows.rk". Besides relative paths, imports may use the aliases of package.json, #ui/button.rk, and of tsconfig.json, @/ui/button.rk: they are typed too.
// Types of node:fs come from @types/node; in the playground, without TypeScript, it is any import { readFileSync } from "node:fs" // Imports of .rk modules are checked: the compiler reads their exports // import { Todo, parseTitle } from "./todos.rk" export interface Config { name string port number } export func loadConfig(path string) (Config, error) { try { return JSON.parse(readFileSync(path, "utf8")), null } catch { return { name: "", port: 0 }, error(`could not read ${path}`) } }