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
Use Cases
Frequently Asked Questions
From the Blog
TypeScript in Practice: Typing Real Applications
TypeScript catches bugs before runtime through three mechanisms working together: structural typing that compares shapes rather than names, inference that types most code without annotations, and strictness flags that decide which unsafe patterns are rejected. This guide shows how to combine them in a real application.
Read More ProgrammingTypeScript for Beginners: JavaScript with a Safety Net
TypeScript adds optional static types to JavaScript, catching bugs before your code runs. This guide explains types, interfaces, generics, and the compile step clearly — with practical examples that show exactly why TypeScript makes large codebases easier to maintain.
Read More ProgrammingTypeScript for Beginners: Why and How
TypeScript adds static types to JavaScript so errors surface while you code, not in production. Learn why teams adopt it and how to start using it today.
Read More ProgrammingTypeScript for JavaScript Developers: A Quick Start
TypeScript adds static types to JavaScript, catching errors before you run code. This quick start covers types, interfaces, generics, and how to add it to a project.
Read More