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.
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…
Ruby1name = "Ada"2puts "Hello, #{name}!"TypeScript1const name: string = "Ada";2console.log(`Hello, ${name}!`);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…
Ruby1puts Integer("12") + 3TypeScript1const value: number = Number("12");2console.log(value + 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…
Ruby1require "json"2puts [1, 2, 3, 4][1..-2].to_jsonTypeScript1const values: number[] = [1, 2, 3, 4];2console.log(JSON.stringify(values.slice(1, -1)));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…
Ruby1total = 02[3, -1, 2].each do |value|3 total += value if value > 04end5puts totalTypeScript1let total: number = 0;2for (const value of [3, -1, 2]) { if (value > 0) total += value; }3console.log(total);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…
Ruby1require "json"2puts [[], 0, ""].map { |value| !!value }.to_jsonTypeScript1const values: unknown[] = [[], 0, ""];2console.log(JSON.stringify(values.map((value) => Boolean(value))));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.…
Ruby1price = 2.52count = 43puts price * countTypeScript1const price: number = 2.5;2const count = 4;3console.log(price * count);
Syllabus
12 chapters48 lessons1 project48 challenges96 quiz questionsStart Here
1 lessonRuntime Values
4 lessonsRuntime Collections
4 lessonsRuntime Control Flow
4 lessonsRuntime Edge Cases
4 lessonsTyped Contracts
5 lessonsTyped Flow
5 lessonsTyped Functions
5 lessonsTyped Collections
5 lessonsReliable Modules and Objects
5 lessonsProject: Typed Orders
4 lessonsFinal Challenges
2 lessonsFrequently 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.