Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Static typing

Статическая типизация

With static typing, a tool checks whether your code uses values in allowed ways before the program runs. For example, it can flag a string passed to a function that requires a number without executing the call.

The basic idea

A type describes what values a piece of code can work with and which operations it can perform on them. If a function takes a list of strings, for example, the type checker can determine that an item read from that list is a string. It can then flag an attempt to pass that item to a function that requires a number, even if no one has run the code yet.

How the checker knows the types

A compiler or a standalone type checker examines the source code. It uses information from declarations and expressions to check assignments, function calls, and return values. Sometimes a developer supplies the type explicitly; other times the tool works it out from the code. This is called type inference, and it saves you from writing annotations without removing the checks.

Example in Go

func double(n int) int {
    return n * 2
}

func main() {
    result := double(21)
    println(result)
    // println(double("21")) // Rejected: string is not an int.
}

The function signature says that double takes an int and returns an int. Go infers that result is an int from the return type, not from running the function and inspecting its output. Uncommenting the last line causes a compile-time error: "21" is a string, and Go does not implicitly parse it as an integer.

Why it matters on a real project

Languages such as Go, Java, Rust, and Kotlin catch many mismatches this way. When you change a function's parameter type, the checker can point to call sites that still pass the old type, including paths your tests never exercise. Editors can also use type information to suggest available methods and fields.

Passing the checker is not the same as passing your tests. If double returns n * 3, the result still has the right type. And if a service receives JSON claiming to contain a numeric price, declaring a Price type does not validate the incoming data. That requires a check at runtime.

How it comes up in interviews

A common follow-up is whether static typing implies that the program compiles to native machine code. It doesn't: static typing is about when type rules are checked, not how the program is executed. TypeScript is a useful example: the checker analyzes the source, but the resulting JavaScript does not enforce TypeScript annotations at runtime.