Menu
CoddyTech
Course

TypeScript for Ruby Developers

Learn the JavaScript runtime and TypeScript contracts from Ruby. Practice typed flow, functions, collections and class modules, then build a validated order-processing tool.

Ruby and TypeScript side by side

The same program in Ruby and in TypeScript, from the lessons of this course.

  1. Run TypeScript

    Ruby is dynamically typed: when a project describes types at all, it does so in separate RBS files or Sorbet sig declarations checked by external tools. TypeScript writes annotations inline and also erases types, but this course runner checks and compiles…

    Ruby
    1name = "Ada"2puts "Hello, #{name}!"
    TypeScript
    1const name: string = "Ada";2console.log(`Hello, ${name}!`);
  2. Numbers and Conversion

    Ruby Integer() and Float() raise ArgumentError for bad numeric strings, while to_i quietly keeps the leading digits. JavaScript Number returns NaN instead, and unexpectedly converts blank text to zero. Ruby raises TypeError for "12" + 3, but JavaScript plus…

    Ruby
    1puts Integer("12") + 3
    TypeScript
    1const value: number = Number("12");2console.log(value + 3);
  3. Arrays and Slice

    Ruby values[1..-2] and values.slice(1, 2) map to JavaScript slice, but Ruby two-argument slice takes a length while JavaScript slice takes an exclusive end index. A negative bracket index such as values[-1] does not retrieve the last element in JavaScript…

    Ruby
    1require "json"2puts [1, 2, 3, 4][1..-2].to_json
    TypeScript
    1const values: number[] = [1, 2, 3, 4];2console.log(JSON.stringify(values.slice(1, -1)));
  4. For-of and Array Values

    Translate Ruby values.each do |value| (or for value in values) to JavaScript for (const value of values). JavaScript for-in looks like Ruby for-in but enumerates property keys, not elements. Braces replace do and end, and for-of already supplies each element…

    Ruby
    1total = 02[3, -1, 2].each do |value|3  total += value if value > 04end5puts total
    TypeScript
    1let total: number = 0;2for (const value of [3, -1, 2]) { if (value > 0) total += value; }3console.log(total);
  5. Truthiness Is Not Emptiness

    Ruby treats only nil and false as falsy, so 0, empty strings, empty arrays and empty hashes are all truthy. JavaScript agrees about empty arrays and objects but treats zero, the empty string and NaN as falsy, so the paired examples intentionally print…

    Ruby
    1require "json"2puts [[], 0, ""].map { |value| !!value }.to_json
    TypeScript
    1const values: unknown[] = [[], 0, ""];2console.log(JSON.stringify(values.map((value) => Boolean(value))));
  6. Annotations and Inference

    Ruby separates arbitrary-precision Integer from Float, and Integer division floors: 7 / 2 is 3. TypeScript number uses JavaScript floating-point arithmetic for both whole and fractional values, so 7 / 2 is 3.5 and a whole result prints as 10, not Ruby's 10.0.…

    Ruby
    1price = 2.52count = 43puts price * count
    TypeScript
    1const price: number = 2.5;2const count = 4;3console.log(price * count);

Syllabus

12 chapters48 lessons1 project48 challenges96 quiz questions

Start Here

1 lesson

Final Challenges

2 lessons

More courses for Ruby developers

Learn TypeScript from another language

Frequently asked questions

Who is TypeScript for Ruby Developers for?

For people who already write Ruby and want to learn TypeScript. Each lesson starts from Ruby you know and shows how TypeScript does the same thing, so you skip the beginner basics.

Do I need to know TypeScript already?

No. The course starts with your first TypeScript program. You need Ruby basics: variables, conditions, loops, functions and collections.

How many lessons does TypeScript for Ruby Developers have?

TypeScript for Ruby Developers contains 48 interactive lessons you can complete at your own pace.

What does TypeScript for Ruby Developers cover?

The course is organized into chapters covering: Start Here, Runtime Values, Runtime Collections, Runtime Control Flow, and more.

Is TypeScript for Ruby Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start TypeScript for Ruby Developers for free

Get started