This a short overview of some of the things you can do with Ezno today. If you find any problems, file an issue.
The following examples show some errors that have been caught using type checking, partial/const evaluation and effects.
To get started we will install oxidation-compiler
which has bindings for Ezno's checker. (you can also get the binary from the releases page).
npm install -g oxidation-compiler@latest
You should now be able to run oxidation-compiler check file.ts
. Append the following statements to file.ts
and watch the checker do its magic ๐ฎ (the whole script + expected output is at the bottom of the page as well)
Constants are treated uniquely
const a: 2 = 4;
Operations on constants use constant functions
const b: 3 = 5 + 2;
Assignments modify the value of variables. The type of variables is based on their current value, which can change.
let c = 5;
c = 3;
let d: 2 = c;
Interfaces are declared the same way as in TS
interface Car {
model: string,
power: number,
weight: number
}
Objects can be checked against it
const car1: Car = { model: "Koenigsegg One:1", power: 1360, weight: 1360 }
Property lookup can find missing names on types
console.lag("log not lag ๐คฆ")
Also using constant addition the following works
const weight: string = car1["we" + "ight"]
Equality is also a constant function, so unnecessary logic can be found.
if (car1.power === car1.weight) {
console.log("always here")
}
Functions with explicit generic parameters can be declared. Using this we can generate a new way to assert something is a type.
function assertType<T>(t: T): void;
Every function parameter is considered generic and so all properties flow through it
function getPerson(name: string) {
return { name }
}
assertType<{name: "not ben" }>(getPerson("Ben"));
some things around effects are currently broken, However this one works
Functions carry effects, which are imperative properties difficult to represent using standard type annotations
function throwValue(value) {
throw value
}
When calling a function, its effects are run. Therefore the following is caught
try {
throwValue("my error")
} catch (e) {
assertType<"different error">(e)
}
Be sure to check out and star ezno as well as oxc if you want to see more!