Stop writing Python in TypeScript.
The whitespace was nice while it lasted. Brace yourself.
Step 1 of 4
Good Python. Dataclasses and isinstance, exactly what you were taught.
@dataclass
class Circle:
radius: float
@dataclass
class Rect:
width: float
height: float
def area(s):
if isinstance(s, Circle):
return pi * s.radius ** 2
return s.width * s.heightYou’d recognize it in review.
Five tells that a TypeScript file was written by a Python dev. They’re all habits Python taught you.
class UserService { constructor() {} }A class with one method and a constructor. That’s just a function returning a typed object.
string | nullNulls everywhere, narrowed by hand. Optional usually means
| undefinedhere, and the difference bites.const name: string = "katie"Annotating what the compiler already knows. Let inference do its job and save the annotations for the boundaries.
try { … } catch (e) { … }try/catch wrapped around code that can’t throw. In Python exceptions are control flow. Here they’re for real failures.
typeof s === "object" && "radius" in sAn isinstance-shaped chain of typeof checks. A
kindfield does this with proof the compiler can read.
Module 01
Unlearning Python.
Module 1 is live. Eleven lessons on the type system. Every exercise runs against the real TypeScript compiler in your browser. Free, no signup. Three more modules are coming. Get those by signing up below.
| 01 | Your TypeScript reads like Python | the thesis |
| 02 | Stop annotating everything | inference is the default |
| 03 | Duck typing, formalized | structural typing |
| 04 | Unions instead of inheritance | the isinstance habit |
| 05 | None, null, undefined: three nothings | Optional[str] ≠ | null |
| 06 | Discriminated unions | the workhorse pattern |
| 07 | Classes everywhere: the Python tell | when a class is still right |
| 08 | unknown vs any | any is worse than untyped Python |
| 09 | Generics without fear | TypeVar → <T> |
| 10 | The pydantic-shaped hole | zod at the boundary |
| 11 | async/await: same keywords, different machine | promises are eager |
Get each module the day it ships.
The whole course is free. Module 1 is open right now, no signup. New modules go out by email first, so if you want Module 2 the day it ships, this is the list.