Why this fires
The value being assigned to a let does not satisfy the declared type annotation:
let x: int = "hello"
// ^^^^^^^ error: type mismatch — expected `int`, found `str`
The type checker compares the right-hand side's inferred type against the annotation and surfaces the first incompatibility.
Fix it
1. Convert the value
If you wrote the wrong literal, fix it. If you have a value of a related type, convert it explicitly:
let x: int = tonumber("42") ?? 0 // str → int
let y: float = 3 // implicit numeric widening
let s: str = tostring(42) // int → str
2. Change the annotation
Sometimes the right-hand side is correct and the annotation was wrong:
let name: str = "hello"
3. Drop the annotation
If you don't need to pin the type, let inference pick it:
let x = 42 // inferred as `int`
let s = "hello" // inferred as `str`
In strict mode, annotations are required — see TE201.
Common variants
- Tuple shape mismatch:
let (a, b): (int, int) = (1, "x")— the second element disagrees. - Optional ↔ non-optional:
let x: int = some_optional— wrap with??to provide a default. - Mutable / immutable confusion: see
TE004.