Type Systems Explained: What Types Actually Do
A type system is a set of rules for classifying values and checking how they combine. Learn static vs dynamic, strong vs weak, and why it matters.
By Velloreth
What a type is
A type is a classification of values, together with the operations that are valid on them.
The number 5 is a number. You can add it, multiply it, compare it. You cannot call it, index it, or iterate it. The type is what tells you which of those operations make sense.
A type system is the set of rules that enforces this. It says: this value is a string, so you may concatenate it but not subtract from it. This function takes two numbers, so calling it with a string is an error.
The purpose is to catch mistakes before they become bugs. A type error is a program that does something meaningless — adding a number to a list, calling a string as a function, accessing a property that does not exist.
Static vs dynamic
The most discussed distinction is when types are checked.
Static typing checks types before the program runs, at compile time. Java, C#, Go, Rust, Swift, Kotlin, and TypeScript are statically typed.
int count = "hello"; // compile error: incompatible types
The error is caught before the program ever executes. You cannot ship this code.
Dynamic typing checks types while the program runs. Python, Ruby, JavaScript, and PHP are dynamically typed.
count = "hello"
count + 1 # TypeError at runtime
The error appears only when that line executes. If the line is in a rarely-used branch, the bug may reach production.
| Static | Dynamic | |
|---|---|---|
| Checked | Before running | While running |
| Errors found | At compile time | At runtime |
| Annotations | Often required | Rarely needed |
| Refactoring | Safer, compiler-guided | Riskier |
| Prototyping | Slower to start | Faster to start |
| Runtime flexibility | Limited | High |
| Tooling | Strong autocomplete | Weaker |
Neither is strictly better. Static typing catches more errors earlier and makes large codebases easier to change. Dynamic typing is faster to write and more flexible, which suits scripts, prototypes, and small codebases.
Strong vs weak
This is a separate axis, and conflating it with static vs dynamic causes a lot of confusion.
Strong typing means the language does not implicitly convert between unrelated types. Weak typing means it does.
// JavaScript: weak
'5' - 1; // 4 — string coerced to number
'5' + 1; // '51' — number coerced to string
[] + {}; // '[object Object]'
# Python: strong
'5' - 1 # TypeError: unsupported operand type(s)
JavaScript is dynamically and weakly typed. Python is dynamically and strongly typed. Java is statically and strongly typed. C is statically and weakly typed — it will happily let you treat an integer as a pointer.
The four combinations all exist, which is why “static vs dynamic” alone does not describe a language.
Type inference
The objection to static typing is verbosity. Type inference removes most of it.
// Without inference
const name: string = 'Ada';
const age: number = 36;
const tags: string[] = ['a', 'b'];
// With inference — identical types, less noise
const name = 'Ada';
const age = 36;
const tags = ['a', 'b'];
The compiler works out the types from the values. You write annotations only where inference cannot help — function parameters, and places where you want to narrow a wider type.
Modern statically typed languages lean heavily on inference. Rust, Go, Swift, and Kotlin all infer local variable types, and TypeScript infers almost everything.
Structural vs nominal typing
Another distinction that matters in practice.
Nominal typing compares types by name. Two types with identical shapes are different if they have different names. Java, C#, and Go (mostly) work this way.
class UserId { String value; }
class OrderId { String value; }
// UserId and OrderId are not interchangeable, even though both wrap a string
Structural typing compares types by shape. If it has the right fields, it is the right type. TypeScript and Go interfaces work this way.
interface Point { x: number; y: number }
function distance(p: Point) { /* ... */ }
distance({ x: 1, y: 2 }); // works — the shape matches
Structural typing is more flexible and requires less ceremony. Nominal typing is more explicit and prevents accidentally passing the wrong thing when two types happen to have the same shape.
What types actually buy you
Errors caught early. A type error is found at compile time rather than in production. The earlier an error is found, the cheaper it is to fix.
Documentation that cannot go stale. A function signature (userId: string) => Promise<User> tells you what it takes and returns. Unlike a comment, the compiler enforces it.
Refactoring confidence. Rename a field and the compiler lists every place that needs updating. In a dynamically typed codebase, you find out by running the tests — or by a production error.
Better tooling. Autocomplete, go-to-definition, and find-references all depend on type information. This is why TypeScript editors feel more capable than plain JavaScript ones.
Performance. In compiled languages, types let the compiler generate specialised code. In JavaScript engines, type feedback from the JIT does the same thing dynamically.
What types do not buy you
Correctness of logic. A function that returns the wrong number has the right type. Types prove shape, not behaviour.
Runtime validation. TypeScript types are erased at runtime. Data from an API is any until you validate it:
const user: User = await response.json(); // no runtime check!
The annotation is a claim, not a verification. You need a schema validator like Zod to actually check.
Freedom from tests. Types and tests catch different things. Types catch structural errors; tests catch behavioural ones. You need both.
Gradual typing
Many languages now allow mixing. TypeScript adds types to JavaScript. Python has type hints. PHP has type declarations. Ruby has Sorbet and RBS.
This lets you add types incrementally, starting with the most valuable parts of a codebase. It is usually the pragmatic choice for an existing project, because a full rewrite is rarely justified.
def greet(name: str) -> str:
return f"Hello, {name}"
Python’s hints are not enforced at runtime by default — they are checked by tools like mypy and pyright. This gives you static analysis without changing the runtime behaviour.
Practical guidance
- Use static typing for large or long-lived codebases. The refactoring safety compounds.
- Use dynamic typing for scripts and prototypes. The speed of iteration matters more.
- Add types gradually to existing projects, starting with boundaries and shared interfaces.
- Validate at runtime even with static types — annotations do not check external data.
- Prefer inference over explicit annotations where the type is obvious.
- Do not fight the type system. If you are casting constantly, the design is probably wrong.
- Remember that types and tests are complementary, not alternatives.
For the practical comparison, see static vs dynamic typing and generics explained. For how types shape design, interfaces vs abstract classes and null vs undefined vs nil.
Quotable summary
A type classifies values and defines which operations are valid on them; a type system enforces those rules. Static typing checks types before the program runs and catches errors at compile time, while dynamic typing checks them at runtime and catches errors as exceptions. Strong versus weak typing is a separate axis describing how readily a language converts between types implicitly, so JavaScript is dynamically and weakly typed while Python is dynamically and strongly typed. Type inference removes most annotation burden from statically typed languages. Types provide early error detection, enforced documentation, refactoring safety, and better tooling, but they prove shape rather than behaviour, and TypeScript’s types are erased at runtime so external data still needs validation.