Primary-constructor classes
Declare class members directly in the constructor signature. val for read-only, var for mutable. No boilerplate.
class User(val id: string, var name: string, val score: int = 0)
val u = User("u1", "Alice")
u.name = "Bob"
Operator overloading
Define arithmetic, comparison, and index operators directly on your types. Shorthand arrow syntax keeps definitions terse.
class Vec2(val x: number, val y: number) {
operator+(b: Vec2) => Vec2(x + b.x, y + b.y)
operator*(s: number) => Vec2(x * s, y * s)
length => Math.hypot(x, y)
}
val v = Vec2(1, 0) + Vec2(0, 1) * 3
Await-less async
sync fun automatically awaits any Promise produced inside the body. Write async logic that reads like sync code — no await keywords needed.
sync fun loadBytes(url: string): Uint8Array {
val res = fetch(url)
return Uint8Array(res.arrayBuffer())
}
Delegated variables
Kotlin-style by delegates let you attach custom read/write behaviour to any variable. Works with React-style state tuples out of the box.
fun useState(init: number) {
return [() => init, (v: number) => { init = v }]
}
var count by useState(0)
count++
console.log(count)
Null-aware access
Optional chaining and nullish coalescing are fully supported. Non-null assertions let you opt out of null checks when you know better.
val city = user.address?.city ?? "Unknown"
val label = maybeUser!.name.toUpperCase()
New-less instantiation
Call constructors without new. Classes and built-ins like Map, Set, and Uint8Array work the same way.
val users = Map<string, User>()
val buf = Uint8Array(1024)
val pt = Point(3, 4)