Menu

1 / 2

Kotlin `apply` / `also` / `with` Don't Translate to TypeScript

DEV Community·Gabriel Anhaia·6 months ago
#QfBEASra
#pipe#typescript#kotlin#programming#user
Reading 0:00
15s threshold

Book: Kotlin and Java to TypeScript

Also by me: The TypeScript Library — the 5-book collection

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

A Kotlin developer joins a TypeScript codebase. They need a User with two fields set, so they write what their fingers know:

val user = User (). apply { name = "alice" age = 30 }

Enter fullscreen mode

Exit fullscreen mode

They translate. There's no apply in TypeScript, so they reach for a builder:

class UserBuilder { private user : Partial < User > = {}; setName ( n : string ) { this . user . name = n ; return this ; } setAge ( a : number ) { this . user . age = a ; return this ; } build (): User { return this . user as User ; } }

const user = new UserBuilder (). setName ( " alice " ). setAge ( 30 ).…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.