Menu
CoddyTech
Course

TypeScript for PHP Developers

Learn the JavaScript runtime and TypeScript contracts from PHP. Compare arrays, object references, null handling, callbacks and interface checks, then build typed modules and a validated order-processing tool.

PHP and TypeScript side by side

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

  1. Run TypeScript

    PHP executes scripts and checks declared parameter and return types at runtime, with scalar coercion rules affected by strict_types. TypeScript also erases types, but this course runner checks and compiles TypeScript before Node executes it. PHP…

    PHP
    1<?php2declare(strict_types=1);3$name = "Ada";4echo "Hello, {$name}!\n";
    TypeScript
    1const name: string = "Ada";2console.log(`Hello, ${name}!`);
  2. Numbers and Conversion

    PHP numeric casts can accept text differently from a strict parser, so this source checks is_numeric before conversion. JavaScript Number returns NaN instead, and unexpectedly converts blank text to zero. Validate blankness and finiteness explicitly. A…

    PHP
    1<?php2declare(strict_types=1);3$text = "12";4if (!is_numeric($text)) throw new InvalidArgumentException("number required");5echo json_encode((float)$text + 3), "\n";
    TypeScript
    1const value: number = Number("12");2console.log(value + 3);
  3. Arrays and Slice

    PHP array_slice takes an offset and length, whereas JavaScript slice takes start and exclusive end indexes. Both can build a new outer collection, but PHP arrays are ordered maps and may have nonconsecutive keys. A negative JavaScript bracket property is not…

    PHP
    1<?php2declare(strict_types=1);3$values = [1, 2, 3, 4];4echo json_encode(array_slice($values, 1, -1)), "\n";
    TypeScript
    1const values: number[] = [1, 2, 3, 4];2console.log(JSON.stringify(values.slice(1, -1)));
  4. For-of and Array Values

    PHP foreach visits values, or keys and values when both bindings are requested. 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. Avoid carrying PHP…

    PHP
    1<?php2declare(strict_types=1);3$total = 0;4foreach ([3, -1, 2] as $value) { if ($value > 0) $total += $value; }5echo $total, "\n";
    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

    PHP empty arrays are falsy, whereas JavaScript empty arrays and objects are truthy. The paired examples intentionally print different booleans. PHP string "0" is also falsy while JavaScript string "0" is truthy, so translate the intended condition explicitly.…

    PHP
    1<?php2declare(strict_types=1);3echo json_encode((bool)[]), "\n";
    TypeScript
    1const value: unknown = [];2console.log(Boolean(value));
  6. Annotations and Inference

    PHP distinguishes int and float at runtime even though variables themselves can hold different types. TypeScript number uses JavaScript floating-point arithmetic for both whole and fractional values. BigInt is a separate runtime type outside these exercises…

    PHP
    1<?php2declare(strict_types=1);3$price = 2.5; $count = 4;4echo json_encode($price * $count), "\n";
    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 PHP developers

Learn TypeScript from another language

Frequently asked questions

Who is TypeScript for PHP Developers for?

For people who already write PHP and want to learn TypeScript. Each lesson starts from PHP 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 PHP basics: variables, conditions, loops, functions and collections.

How many lessons does TypeScript for PHP Developers have?

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

What does TypeScript for PHP Developers cover?

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

Is TypeScript for PHP 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 PHP Developers for free

Get started