Skip to content
Latchkey

Elm "-- TYPE MISMATCH" in CI

Elm's type checker found an expression whose inferred type does not match what the context requires. "-- TYPE MISMATCH" prints the two types and points at the exact subexpression that disagrees.

What this error means

elm make stops with "-- TYPE MISMATCH" and a "The X value is a: ... But Y needs it to be: ..." block under the offending expression.

elm
-- TYPE MISMATCH ------------------------------------------- src/Main.elm

The 1st argument to `text` is not what I expect:

    text count

This `count` value is a:

    Int

But `text` needs the 1st argument to be:

    String

Common causes

A value of the wrong type is passed

The expression has one type (here Int) but the function expects another (String), so no conversion exists implicitly.

A record or union shape changed

A field or constructor was added, removed, or renamed, so a call site now supplies a value the function no longer accepts.

How to fix it

Convert or correct the value

  1. Read the "is a" versus "needs it to be" types in the message.
  2. Insert the right conversion (for example String.fromInt count).
  3. Re-run elm make to confirm the types now align.
src/Main.elm
text (String.fromInt count)

Update the type or its call sites

If a record or custom type changed shape, update every site that builds or pattern-matches it so the types are consistent again.

How to prevent it

  • Add explicit top-level type annotations so mismatches localize.
  • Compile locally before pushing; Elm has no runtime type errors to fall back on.
  • Update all call sites when a record or union type changes.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →