A type system assigns types to expressions and enforces type compatibility. Static type systems check types at compile-time, preventing type errors before runtime. Strongly-typed languages reject invalid operations; weakly-typed languages attempt coercions. Type systems vary in expressiveness: simple (int, float, bool), composite (structs, classes), and advanced (generics, dependent types).
After semantic analysis assigns meaning to identifiers and scopes, a compiler's type checker asks the next question: does every operation make sense for the kinds of values involved? This is what a type system formalizes. A type is a set of values with associated operations — `int` is a set of integers you can add and multiply; `string` is a sequence of characters you can concatenate. The type system's job is to ensure you never accidentally mix them up.
The most important distinction to internalize is that static vs. dynamic typing and strong vs. weak typing are two separate axes, not a single spectrum. Static typing means the type of every expression is known at compile time; the compiler rejects the program if types are incompatible. Dynamic typing means types are attached to values at runtime and checked when operations execute. These are independent of whether the language is strongly typed (refuses to coerce mismatched types, like Python rejecting `1 + "hello"`) or weakly typed (attempts implicit conversion, like JavaScript silently computing `1 + "hello"` as `"1hello"`). Java is static and strong. Python is dynamic and strong. C is static and weak. JavaScript is dynamic and weak.
Type systems also vary in what they can express. Simple types — `int`, `float`, `bool` — let you describe basic values. Composite types — structs, classes, tuples — let you bundle values together. Polymorphic or generic types (like `List<T>`) let you write code that works for any type T without sacrificing type safety. More advanced systems (dependent types, linear types) can encode program invariants like "this array has exactly n elements" directly in the type, letting the compiler verify properties that would otherwise require runtime checks or manual proof.
From the compiler's perspective, the type system operates during semantic analysis. After parsing produces an AST and name resolution links identifiers to their declarations, the type checker annotates each AST node with a type, then verifies that every operator's arguments match its expected types. When a type error is found, the compiler reports it with a source location rather than crashing at runtime. This is why type errors are considered a *compile-time* benefit of static languages.
Understanding type systems is the foundation for more advanced topics: type inference (having the compiler deduce types you didn't write), parametric polymorphism (generic functions that remain type-safe), and eventually dependent or refinement types. Each of these extends the basic idea — that a type is a formal constraint on what values an expression can hold — into more expressive territory.