Skip to content
ZOLO / TE002 Type · error

type mismatch in `const` binding

The value assigned to a `const` binding does not satisfy the declared type annotation.

Why this fires

A const declaration has an explicit type annotation, but the value's inferred type is not assignable to it.

const MAX: int = "one hundred"
//              ^^^^^^^^^^^^^ error[TE002]: type mismatch in const: expected int, found str

const bindings are checked the same way let bindings are (see TE001) — the only difference is that the value must also be a compile-time constant expression (that separate rule is TE003).

Fix it

1. Fix the value

const MAX: int = 100          // ok

2. Fix the annotation

If the annotation was wrong and the value is the one you want to keep:

const LABEL: str = "one hundred"   // ok

3. Drop the annotation and let it infer

const MAX = 100                // ok — type is inferred as int

See also

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br