TypeScript for Lua Developers
Learn the JavaScript runtime and TypeScript contracts from Lua. Compare tables, truthiness, closures, missing values and module conventions, then build typed modules and a validated order-processing tool.
Lua and TypeScript side by side
The same program in Lua and in TypeScript, from the lessons of this course.
Run TypeScript
Lua executes chunks and uses local bindings; standard Lua has no TypeScript-style static annotation syntax. TypeScript also erases types, but this course runner checks and compiles TypeScript before Node executes it. Braces replace Lua end-delimited blocks.…
Lua1local name = "Ada"2print("Hello, " .. name .. "!")TypeScript1const name: string = "Ada";2console.log(`Hello, ${name}!`);Numbers and Conversion
Lua tonumber returns nil when conversion fails; callers must check before arithmetic. JavaScript Number returns NaN instead, and unexpectedly converts blank text to zero. Validate blankness and finiteness explicitly. A TypeScript annotation does not perform…
Lua1local value = assert(tonumber("12"))2print(value + 3)TypeScript1const value: number = Number("12");2console.log(value + 3);Arrays and Slice
Lua dense sequences conventionally start at index one, and a loop can copy their middle entries. Negative table keys are independent keys rather than end offsets. JavaScript arrays start at zero; slice creates a shallow range copy. Use at(-1) or an explicit…
Lua1local values = {1, 2, 3, 4}2local middle = {}3for i = 2, #values - 1 do middle[#middle + 1] = values[i] end4print("[" .. table.concat(middle, ",") .. "]")TypeScript1const values: number[] = [1, 2, 3, 4];2console.log(JSON.stringify(values.slice(1, -1)));For-of and Array Values
Lua ipairs traverses consecutive integer keys starting at one and stops at the first missing entry. JavaScript for-of visits array values, while for-in enumerates keys. There is no built-in range syntax required here: for-of already supplies each element.…
Lua1local total = 02for _, value in ipairs({3, -1, 2}) do3 if value > 0 then total = total + value end4end5print(total)TypeScript1let total: number = 0;2for (const value of [3, -1, 2]) { if (value > 0) total += value; }3console.log(total);Truthiness Is Not Emptiness
In Lua only nil and false are falsy; even zero, empty text and empty tables are truthy. JavaScript also treats empty arrays as truthy, but zero and empty text are falsy. Test sequence length explicitly when asking whether a dense Lua sequence or JavaScript…
Lua1local values = {}2print(not not values)TypeScript1const value: unknown = [];2console.log(Boolean(value));Annotations and Inference
Lua 5.4 distinguishes integer and floating-point numeric subtypes; this multiplication uses a floating operand. TypeScript number uses JavaScript floating-point arithmetic for both whole and fractional values. BigInt is a separate runtime type outside these…
Lua1local price, count = 2.5, 42print(string.format("%g", price * count))TypeScript1const 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 Lua Developers for?
For people who already write Lua and want to learn TypeScript. Each lesson starts from Lua 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 Lua basics: variables, conditions, loops, functions and collections.
How many lessons does TypeScript for Lua Developers have?
TypeScript for Lua Developers contains 48 interactive lessons you can complete at your own pace.
What does TypeScript for Lua Developers cover?
The course is organized into chapters covering: Start Here, Runtime Values, Runtime Collections, Runtime Control Flow, and more.
Is TypeScript for Lua Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.