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/elsebranches 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
stringis 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 forint,bool,float, ornull— usetoStringfor those. -
String interpolation as path — When a string interpolation like
"${expr}/suffix"is used where apathis 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/elseshould 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.