gen-ts: a spec becomes TypeScript
You will learn
What gen-ts writes for constants and functions, and how a host program uses it.
t27c gen-ts turns each constant into an export const line that TypeScript type-checks. Functions are not emitted: the backend says it lowers declarations, not bodies. This is how this site uses specs: a generator reads a .t27 file and writes the numbers and words a page imports. The table under this lesson shows what gen-ts wrote for the lesson spec.
Try it
Add a constant to the lesson spec in the player and find its line in the ts tab.

The TypeScript the real t27 compiler wrote for the lesson spec, line by line next to its source. Lesson 21 of the t27 basics course.
specs/basics/21_gen_ts.t27
// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 21: gen-ts: a spec becomes TypeScript.
; gen-ts writes the constants of a spec as TypeScript, and leaves function bodies out.
module basics_21_gen_ts;
pub const WIDTH : u8 = 8;
pub const NAME : str = "basics";
pub fn add(a: u8, b: u8) -> u8 {
return a + b;
}
test width_is_a_byte {
assert WIDTH == 8;
}
All lessons
Module 1 · A spec file
What a .t27 file holds: a module line, prose lines and comments.
Module 2 · Values and types
Constants, the width of a whole number, and true, false and text.
Module 3 · Arrays, trits and expressions
Lists of values, the three values of a trit, and what operators compute.
Module 4 · Tests and functions
A test block, several small tests in one spec, and a function with typed inputs.
Module 5 · Inside a function
Names with let and var, choices with if and switch, and loops.
Module 6 · Visibility and your own types
What pub shares with other modules, and the structs and enums you declare.
Module 7 · Modules, rules and gen-ts
Reading another module, stating a rule that always holds, and a spec turned into TypeScript.
Module 8 · The compiler and tri
The backends t27c writes, the stages it reads a spec in, and the tri command.
Module 9 · Errors, a program, what next
Reading a compiler error, one small complete program, and the course to take next.