# Type Inference

> The language works out each value's type. You do not have to write it.

**Field:** Software Development  
**Category:** Programming Paradigms  
**Also known as:** Inferred Type, Type Deduction

## Think of it like

Think of it like a box shaped for shoes. You can guess what is in it.

## Definition

Type inference is when the language works out a value's type without you writing it. If you write let count = 5, TypeScript knows count is a number. From then on it holds you to that, so putting text in count is an error. You get the safety of types with less typing. Go, Rust, Kotlin, Swift and TypeScript all do it.

## Example

Emma writes let count = 5 and later sets count to the word five. TypeScript stops her, though she never wrote number anywhere.

## Example code

```typescript
let count = 5;
count = "five";
// Type 'string' is not assignable to type 'number'.
```

TypeScript guessed number from the 5, and refuses the text.

## Why it matters

It keeps typed code short. You write types where they help a reader, and let the language fill in the rest.

## Common mistake

Thinking an inferred type is a loose type. Once inferred, it is checked just as strictly as one you wrote.

## Three principles

- **Worked out for you.** From the value you give.
- **Still strict.** Checked like a written type.
- **Less to type.** Same safety.

## Related terms

- [Type Annotation](https://learn.benibix.com/term/development/type-annotation)
- [Type System](https://learn.benibix.com/term/development/type-system)
- [TypeScript](https://learn.benibix.com/term/development/typescript)
- [Statically Typed Language](https://learn.benibix.com/term/development/statically-typed-language)

## Told apart from

- [Type Annotation vs Type Inference](https://learn.benibix.com/compare/type-annotation-vs-type-inference): People think a typed language makes you write a type on every name, and it does not. A type annotation is a type you write yourself, such as count: number. Type inference is the language working the type out from the value, so let count = 0 is already a number. Most code uses both, with notes where they help the reader.

---

Source: https://learn.benibix.com/term/development/type-inference
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
