Skip to content
Lucent
SEARCH LUCENT

Search guides, APIs, and examples.

GitHub

Very early and experimental. The language, the generated native code and every package API change without notice. Do not use Lucent in production.

What changes from JavaScript

Lucent is TypeScript whose every value has a native type: no any, no dynamic property access, no eval, and JavaScript's exact number semantics.

Lucent compiles every value to a native type known at build time. The rules below follow from that, and each break is a compile error with a LUCENT code.

In JavaScriptIn LucentWhy
anya concrete type, a union or a generic (LUCENT2001)Native code needs each value's layout.
obj[key] on an object typea Record<string, T> or a Map (LUCENT1001)An object type is a C++ struct with fixed fields.
an object literal with methods or gettersa class (LUCENT2002, LUCENT1001)Methods live on classes.
varlet or const (LUCENT1001)One scoping rule.
eval, new Functionnot available (LUCENT1003)No JavaScript engine runs in native code.
JSON.parse(text)JSON.parse(text) as SettingsThe result is checked against the type, and a mismatch throws.
throw "oops"throw error("E_OOPS", "Oops") (LUCENT1006)Only Error values cross the boundary with a message and a code.
Promise.race, .thenawait, Promise.all (LUCENT1003)Not implemented yet.
xs.toSorted()[...xs].sort()The ES2023 methods aren't available yet.
settings.lucent.ts
export type Settings = { theme: string; size: number };
export function parseSettings(text: string): Settings {
return JSON.parse(text) as Settings; // throws a TypeError naming the bad field
}

A number is a 64-bit float with JavaScript's arithmetic, rounding and formatting: 0.1 + 0.2 is 0.30000000000000004, as in JavaScript. Locals that only hold integers are stored as integers, with the same results.

A native 64-bit integer, such as a Java long or an NSInteger count, is a bigint, so no value is rounded. Number(list.count) makes it a number when you need one.

Where Lucent does behave differently from JavaScript, the list of differences has each case and its reason.