t27.aiРусский

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.

Open the interactive lesson →

t27 basics 21: what gen-ts writes
t27 basics 21: what gen-ts writes ↗

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;
}

Open the lesson's spec in the player ↗

All lessons