Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

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

DEV Community·Gabriel Anhaia·about 1 month 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. The user gets created without an email.…

Continue reading — create a free account

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

Read More