Menu

1 / 2

From `String?` to `string | null | undefined` for Kotliners

DEV Community·Gabriel Anhaia·6 months ago
#IMVTD4CI
Reading 0:00
15s threshold

Book: Kotlin and Java to TypeScript — A Bridge for JVM Developers

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 service. Day one, they model a user.

data class User ( val id : Long , val email : String ?, )

Enter fullscreen mode

Exit fullscreen mode

Two minutes of thought. email is sometimes there, sometimes not. The compiler will refuse to let anyone touch user.email.length without a null check. Done.

Day two, they translate the same shape to TypeScript and pick the literal-looking option:

interface User { id : number ; email : string | null ; }

Enter fullscreen mode

Exit fullscreen mode

The service serializes a user with email = null , sends the JSON over the wire to a frontend, and the frontend reads user.email and gets undefined . The form initializes blank. Validation passes.…

Continue reading — create a free account

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