What does "static typing" mean?
Static typing means that the data type of a variable, parameter, or expression is checked at compile time, before the program runs.
In simpler terms, TypeScript (or another statically typed language) "checks types ahead of time", not while the code is running.
1. Example without static typing (JavaScript)
let name = "Alice";
name = 123; // allowed, JS does not check types
console.log(name.toUpperCase()); // Runtime errorIn JavaScript the error appears only when the program runs, because the type of
nameis not fixed.
2. Example with static typing (TypeScript)
let name: string = "Alice";
name = 123; // Compile error: string expectedTypeScript reports the error before the code even runs, preventing bugs in advance. The compiler simply will not let you build a project with such a type mismatch.
3. The main idea
With static typing:
- types are known ahead of time (at compile time);
- type errors are caught before the program runs;
- the IDE and compiler can provide hints, autocomplete, and navigation.
4. The opposite: dynamic typing
| Approach | When types are checked | Example languages | Example error |
|---|---|---|---|
| Static typing | at compile time | TypeScript, Java, C# | Error: "expected string, got number" |
| Dynamic typing | at runtime | JavaScript, Python | Error while the program runs |
5. Advantages of static typing
- Early error detection
- Convenient IDE hints
- Better readability and predictability of code
- Safe refactoring and scaling of the project
In short:
Static typing is a mechanism that guarantees type correctness before the program runs, helping avoid many errors already at the development stage.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.