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.

Language features

Every TypeScript feature: whether Lucent supports it, and what to write instead when it doesn't.

FeatureSupportedNote
export function, export class, export const, export letyesWhat JavaScript can use. Constants cross once, when the module loads.
export type, export interface, export enumyesEnums reach JavaScript as frozen objects. Their values aren't checked at the boundary.
Imports between modules, import typeyesRelative imports of other *.lucent.ts files, and lucent:* modules.
Imports of npm packagesnoOnly other modules and lucent:* (LUCENT3001).
export default, export { … }, export * fromnoExport each declaration where it's declared (LUCENT3003).
Components: an exported function of a .lucent.tsx module that returns a platform viewnoNot rendered yet. Lucent checks them (LUCENT3020 to LUCENT3023) and leaves them out of the module's JavaScript.
Top-level statementsnoOnly declarations at the top level (LUCENT3002).
varnoUse let or const (LUCENT1001).
FeatureSupportedNote
number, string, boolean, null, undefinedyesA number is a double with JavaScript's arithmetic.
bigintyesAny precision; values that fit in 64 bits don't allocate. Loose == with a number or string is rejected (LUCENT1002).
Object types, interfaces without methodsyesBecome C++ structs, one per shape.
Arrays, tuples, Record<string, T>, Map, Set, Uint8Array, Date, RegExpyesReference types, shared inside Lucent as in JavaScript.
Unions and discriminated unionsyesNarrowed by typeof, instanceof, a discriminant field, or a null check.
Optional fields and parameters, T | null, T | undefinedyes
GenericsyesFunctions, classes and interfaces. Not exported to JavaScript (LUCENT2007).
String literal typesyesChecked by TypeScript; at the boundary, any string is accepted.
any, and unknown outside catchnoUse a concrete type, a union or a generic (LUCENT2001).
Intersections, object, symbolnoNo native representation (LUCENT2002).
Object types with methods or gettersnoUse a class (LUCENT2002).
WeakMap, WeakRef, typed arrays other than Uint8ArraynoLUCENT2002.
FeatureSupportedNote
if, switch, for, for…of, for…in, while, do…while, labelsyes
try, catch, finally, throwyesOnly Error values can be thrown (LUCENT1006).
using declarationsyesDisposed by a class's [Symbol.dispose]() on every way out of the block. Not await using, or using directly in a case clause (LUCENT1001).
Every operator, ??, ?., !, **, logical assignmentyes! throws a TypeError when the value is missing. === compares arrays, maps, sets, records and class instances by reference, tuples by their elements; functions cannot be compared (LUCENT1002).
Template literals, spread, destructuringyesNot object rest or computed keys in destructuring (LUCENT1004).
obj[key] with a computed key on an object typenoUse a Record or a Map (LUCENT1001).
deleteyesOn a Record. Use Map.delete for maps.
inyesOn a Record only (LUCENT1002).
eval, new FunctionnoLUCENT1003.
for awaitnoLUCENT1009.
FeatureSupportedNote
Function declarations, arrows, closures, recursionyesClosures share the variables they capture.
Default and rest parametersyesNot rest parameters in function types (LUCENT2002).
Generators, yield, yield*yesNot the value of yield, a generator's return value, or async generators.
Classes: fields, constructors, methods, getters, setters, static, private, #privateyes
extends a Lucent class, extends Error, abstractyes
implements an interfaceyesNeeded to use a class as the interface (LUCENT2008).
Nested classes, static blocks, index signatures on classesnoLUCENT1001, LUCENT1005.
call, apply, bind, this outside a classnoLUCENT1003, LUCENT1001.
Object literals with methods, getters or settersnoUse a class (LUCENT1001, LUCENT2002).
FeatureSupportedNote
async functions and methods, awaityesExported ones run on the Lucent thread.
Promise.all, Promise.resolve, Promise.reject, new Promiseyes
Promise.race, Promise.allSettled, Promise.any, .thennoLUCENT1003.
AbortSignal, AbortControlleryesaborted, throwIfAborted(), addEventListener("abort", …). Not signal.reason.
JavaScriptLucent
arr[i] = v past the end makes holesthrows a RangeError; append with push
values passed to native code are sharedcopied at the boundary; shared inside Lucent
garbage collection frees cyclesreference counting never frees a cycle
deep recursion throws a RangeErrormay overflow the native stack
== converts between numbers, strings and booleans (1 == "1")such comparisons are refused (LUCENT1002); compare with === after converting
functions compare by referencecomparing two functions is refused (LUCENT1002): a function value has no stable identity
tuples are arrays and compare by referencetuples are values: === compares their elements
two subarray() views of one range are different objectsthey are one view: === compares a view's buffer and range
console.log(obj) pretty-printsprints String(obj)
str.split(regexp) gives undefined for a group that didn't matchgives ""
JSON.parse returns whatever the text holdsthe text must match the type; a mismatch throws a TypeError naming the path
JSON.stringify keeps the parsed text's key orderkeys follow the declared type's order
an abort reason can be any valuereasons from JavaScript become errors; abort() in Lucent takes an Error
a subclass field read from the base constructor is undefinedit reads the type's default: 0, "", false
any object with the right members fits an interfaceonly classes that declare implements