Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E001: Type Mismatch

Severity: Error

type mismatch: expected `string`, got `int`

A value was used where a different type was expected. This is the most common error – it means the inferred type of an expression is incompatible with how it’s being used.

Common causes

  • Passing an argument of the wrong type to a function:
    let f = x: x + "hello"; in f 42
    # f expects a string (because of ++), but got int
    
  • Returning inconsistent types from if/else branches when the consumer expects a specific type.
  • Accessing a field and using it as the wrong type.

Hints

E001 may include a contextual hint when tix recognises a common pattern:

  • String coercion — When a non-string value (e.g., a derivation or path) is passed where string is expected, Nix would silently coerce it at runtime. Tix flags this so you can make the conversion explicit:

    # Before (E001):
    lib.optionalString true myDerivation
    
    # Fix with toString:
    lib.optionalString true (toString myDerivation)
    
    # Or with string interpolation (works for paths and derivations):
    lib.optionalString true "${myDerivation}"
    

    String interpolation ("${...}") works for paths and attrsets (derivations) but not for int, bool, float, or null — use toString for those.

  • String interpolation as path — When a string interpolation like "${expr}/suffix" is used where a path is expected, tix suggests using path concatenation (expr + "/suffix") instead.

How to fix

  • Check the expected and actual types in the error message and trace back which expression produces the wrong type.
  • If both branches of an if/else should return the same type, make sure they do.
  • If the mismatch comes from an import, add a type annotation to clarify the imported value’s type.