Static Typing
Static typing is a language design approach in which the type of every variable is known and checked at compile time, before the program runs.
Definition
Static typing is a language design approach in which the type of every variable is known and checked at compile time, before the program runs.
Overview
In a statically typed language such as Java, C++, Go, or TypeScript, every variable, function parameter, and return value has a type that is either declared explicitly or determined by the compiler through type inference. The compiler checks that operations are used consistently with those types before the program ever executes, so many category of bugs — such as calling a method that does not exist on a given type, or passing a string where a number is expected — are caught immediately as compile errors rather than surfacing later at runtime. This upfront checking has practical benefits beyond catching bugs early: it gives tooling like IDEs precise information to offer accurate autocomplete, safe automated refactoring, and reliable “go to definition” navigation, since the type of every expression is known ahead of time. It also serves as a form of documentation, making function signatures self-describing about what kinds of values they accept and return. The trade-off is more upfront ceremony: developers must write type annotations (or rely on inference) and satisfy the compiler before code will even run, which can slow down quick prototyping compared to dynamic typing. Many modern static languages soften this cost significantly through strong type inference, and hybrid approaches like TypeScript let teams add static typing incrementally on top of a dynamically typed language like JavaScript, gaining much of the safety without a full rewrite.
Key Concepts
- Types are checked at compile time, before the program runs
- Type errors are caught as compile errors rather than runtime failures
- Enables precise IDE tooling: autocomplete, safe refactoring, and navigation
- Function signatures document expected input and output types
- Used by languages such as Java, C++, Go, Rust, and TypeScript
- Requires explicit annotations or relies on compiler type inference
- Generally trades some prototyping speed for stronger compile-time safety