☕ Java → TypeScript: Great News — Very Similar!
Java → TypeScript: Great News — Very: TypeScript is much easier for Java developers than Python! class, interface, access modifiers, generics, enums — all will feel familiar.
TypeScript is much easier for Java developers than Python! class, interface, access modifiers, generics, enums — all will feel familiar. There are only a few critical differences. This section explains these differences from a Java perspective.
1. Basic Types — Very Similar to Java
In Java there are separate numeric types: int, long, float, double. TypeScript uses a single type for all numbers: number. string is lowercase (not Java's String object), and boolean is identical.
"number" = all of Java's int/long/float/double in one type. "string" (lowercase) ≠ Java String (uppercase). TypeScript also has "any" (like Object — an escape hatch, avoid it!) and "unknown" (safer any).
2. Interface — Structural Typing (The Most Important Difference!)
TypeScript interfaces look like Java's but have one critical difference: TypeScript uses structural typing. An object does NOT need to declare "implements" — any object with the right shape satisfies the interface.
Java = nominal typing ("implements" declaration required). TypeScript = structural typing ("having the right shape is enough"). This is TypeScript's most powerful and most distinctive concept.
3. Classes — Nearly Identical!
TypeScript class syntax is so similar to Java that there are only minor differences: the "constructor" keyword, "readonly" (instead of final), and constructor shorthand (declare and assign in one line).
"readonly" = Java "final". Constructor shorthand: "constructor(private x: T)" both declares the field and assigns it — a big boilerplate saving compared to Java.
4. Access Modifiers — Identical!
TypeScript access modifiers use the exact same keywords as Java: public, private, protected. Unlike Java there is no "package-private". And good news: unlike Python, TypeScript actually enforces this at compile time!
TypeScript enforces private/protected at compile time (like Java). Unlike Python, this is a real constraint. No "package-private" — for internal module use, simply don't export.
5. Generics — Very Similar to Java Generics