Skip to main content

Static Typing

Static typing checks types at compile time before execution, catching type errors early and enabling strong tooling, at the cost of more upfront annotation.

Static typing means a program's types are determined and verified at compile time, before it executes. Each variable, parameter, and expression has a type the compiler can check, so attempts to misuse a value — like calling a string method on a number — are caught during the build rather than at run time. Java, C#, Go, Rust, Kotlin, and TypeScript are statically typed.

How It Works

The programmer either annotates types explicitly or relies on type inference, where the compiler deduces them. During compilation, the type checker verifies every operation against the declared or inferred types and rejects code that violates the rules. Because the types are fixed, the resulting program does not need to carry type information for safety checks at run time (though it may for other reasons), and compilers can use type knowledge to generate more efficient code.

Why It Matters

Static typing shifts a whole class of bugs to the earliest possible moment — the build. Whole categories of mistakes, such as typos in field names or passing arguments in the wrong order, simply cannot compile. The types also power rich tooling: precise autocomplete, safe automated refactoring, and accurate navigation. On large codebases and teams, this early checking and tooling support significantly improve maintainability.

The trade-offs are more upfront ceremony and sometimes reduced flexibility compared to dynamic typing. Modern type inference and gradual typing narrow this gap considerably.

Related Terms

Dynamic typing checks types at run time instead. Type system is the broader framework. Compilation is when static checks run, and they complement, but do not replace, unit tests.