Kick off your book project in 3 hours! Live workshop on Zoom. You’ll leave with a real book project, progress on your first chapter, and a clear plan to keep going. Saturday, June 6, 2026. Learn more…

Leanpub Header

Skip to main content

From Ruby to TypeScript

This book is 100% completeLast updated on 2026-05-28

This book is built on one idea: the fastest way for a Rubyist to learn TypeScript is to map every TypeScript concept back to Ruby. Each chapter starts with Ruby code you already understand, then shows the TypeScript equivalent. You’re not learning from scratch — you’re translating.

Take everything you know about Ruby — classes, hashes, exceptions, enumerable methods, blocks — and translate it directly to TypeScript. No fluff, no abstract theory, just runnable Ruby-to-TypeScript comparisons with hands-on exercises.

Minimum price

$19.00

$29.00

You pay

Author earns

$
PDF
EPUB
WEB
About

About

About the Book

Learning a new programming language is hard. Learning one that adds a whole type system on top of JavaScript — while also introducing async/await, a new module system, and a different runtime — is harder.

From Ruby to TypeScript skips the abstract theory and teaches TypeScript the way a Rubyist actually learns: by mapping every TypeScript concept back to Ruby. `console.log` replaces `puts`. Template literals replace string interpolation. `interface` replaces duck typing. `async/await` replaces threads and fibers. `try/catch` replaces `begin/rescue`. And types — the biggest mental shift — are introduced step by step, with Ruby analogies at every turn.

Each chapter starts with Ruby code you already understand, then shows the TypeScript equivalent — complete, runnable, and explained line by line. You'll build types, classes, interfaces, async pipelines, and generics from the ground up, with hands-on exercises at every step.

TypeScript has become the lingua franca of modern web development. React, Next.js, Angular, Vue, Deno, Bun, VS Code — all built with TypeScript. Companies like Airbnb, Shopify, Slack, and Microsoft run it in production at scale. It has been battle-tested and proven — a mature, powerful language to build your career on.

Updated for TypeScript 5.x, this edition covers strict mode, ES modules, async/await, discriminated unions, utility types, generics, Zod validation, and the modern toolchain (`tsx`, `ts-node`, `vitest`) — everything you need to write production TypeScript in 2026.

This book was written with a Rubyist in mind. Every learning metaphor is based on Ruby. If you know Ruby and want to add TypeScript to your toolkit — for full-stack development, backend services, or your next career move — this is the book.

Share this book

Categories

Author

About the Author

Joel Bryan Juliano

Hi, I'm Joel.

I am Senior Software Engineer with 20+ years of experience.

And with over 20 years in the game, I’ve seen it all and loved every minute of it.

Originally from the Philippines, I am now a Dutchman living in Amsterdam together with my family.

My journey has taken me through a variety of industries, from sports streaming to cybersecurity, and everything in between.

Along the way, I’ve picked up a diverse set of skills and experiences, in which I document into books.

Contents

Table of Contents

Preface

Introduction

  1. Who This Book Is For
  2. How to Use This Book
  3. What This Book Is Not
  4. A Note on Runtime
  5. About the Author

Chapter 1: Getting Started

  1. Installing Node.js and a TypeScript Runner
  2. Your First TypeScript Program
  3. Template Literals: String Interpolation
  4. Variables: const and let
  5. Type Annotations (Your First Taste)
  6. Functions
  7. Arrow Functions
  8. The Entry Point
  9. tsconfig.json: Project Configuration
  10. Chapter Exercises
  11. Summary

Chapter 2: Types & Type Annotations

  1. The Basic Types
  2. Type Annotations
  3. Type Inference
  4. null and undefined
  5. Union Types
  6. Literal Types and Enums
  7. Type Aliases
  8. any and unknown
  9. Type Assertions
  10. Chapter Exercises
  11. Summary

Chapter 3: Arrays, Tuples & Iteration

  1. Typed Arrays
  2. Mixed-Type Arrays
  3. Tuples
  4. readonly Arrays and Tuples
  5. Iteration: for…of (The Each Replacement)
  6. forEach: Each with an Index
  7. Traditional for Loop (C-Style)
  8. map: Transform Every Element
  9. filter: Select Elements
  10. reduce: Aggregate Values
  11. some and every: Predicate Checks
  12. Spread and Rest: The Splat Operator
  13. Chapter Exercises
  14. Summary

Chapter 4: Objects, Records & Maps

  1. Object Types: The Hash Replacement
  2. Optional Properties
  3. Index Signatures: Hash-Like Objects
  4. Record: Typed Hash
  5. Map: When Keys Are Dynamic
  6. Set: Unique Collections
  7. Object Destructuring: Hash Splat
  8. Spread: Merging Objects
  9. readonly Properties
  10. Chapter Exercises
  11. Summary

Chapter 5: Functions Deep Dive

  1. Function Declarations vs Arrow Functions
  2. Typed Parameters and Return Types
  3. Optional and Default Parameters
  4. Rest Parameters: Ruby’s Splat
  5. Callbacks and Function Types
  6. Void and Never Return Types
  7. Function Overloads
  8. Chapter Exercises
  9. Summary

Chapter 6: Classes

  1. A Ruby Class, Translated
  2. Access Modifiers: public, private, protected
  3. JavaScript Private Fields (#)
  4. Parameter Properties (Shorthand)
  5. Inheritance: extends
  6. Abstract Classes
  7. Getters and Setters
  8. this and Arrow Functions
  9. Chapter Exercises
  10. Summary

Chapter 7: Interfaces & Type Aliases

  1. Interfaces: The Basics
  2. interface vs type
  3. Extending Interfaces
  4. Optional and readonly Properties in Interfaces
  5. Index Signatures in Interfaces
  6. Structural Typing in Practice
  7. When Interfaces Feel Like Ruby Modules
  8. Chapter Exercises
  9. Summary

Chapter 8: Modules & Package Management

  1. import and export: The New require
  2. Named Exports vs Default Exports
  3. Re-exports and Barrel Files
  4. package.json: The Gemfile
  5. npm, Yarn, and pnpm
  6. node_modules and the Magic of Resolution
  7. Your First TypeScript Project (Walkthrough)
  8. tsconfig.json Paths: Module Aliases
  9. Installing Type Definitions
  10. Chapter Exercises
  11. Summary

Chapter 9: Error Handling

  1. try/catch/finally: The Direct Mapping
  2. Typed Catch with instanceof
  3. Custom Error Classes
  4. The TypeScript Way: Errors as Values
  5. Strict Null Checks: Eliminating NoMethodError on nil
  6. Optional Chaining: Safe Navigation
  7. Nullish Coalescing: The || Alternative
  8. Chapter Exercises
  9. Summary

Chapter 10: Async Programming

  1. The Event Loop
  2. Callbacks and Callback Hell
  3. Promises: The Foundation
  4. async/await: Write Async Code That Looks Synchronous
  5. The async Main Function
  6. Async Iteration
  7. Ruby Threads vs TypeScript Promises
  8. Chapter Exercises
  9. Summary

Chapter 11: JSON & Type Narrowing

  1. JSON.stringify: Value to JSON
  2. JSON.parse: JSON to Value (and the any Problem)
  3. Type Assertions: Trust Me
  4. Type Guards: Prove It at Runtime
  5. Zod: Schema Validation
  6. Discriminated Unions: The JSON Pattern
  7. Working with Unknown JSON Shapes
  8. Chapter Exercises
  9. Summary

Chapter 12: Generics & Utility Types

  1. The Problem Generics Solve
  2. Generic Functions
  3. Generic Interfaces and Types
  4. Generic Constraints
  5. Built-in Utility Types
  6. Generics vs Duck Typing
  7. Chapter Exercises
  8. Summary

Appendix A: Ruby ↔ TypeScript Quick Reference

  1. Syntax & Structure
  2. Variables & Types
  3. Data Structures
  4. Functions & Methods
  5. Error Handling
  6. Concurrency & Async
  7. Modules & Packages
  8. Common Patterns
  9. TypeScript CLI Cheat Sheet
  10. File Layout

Glossary

Acknowledgements

Credits

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub