F# "error FS0001: This expression was expected to have type" in CI
F#'s type inference found an expression whose type does not match its context. FS0001 prints the expected and actual types and points at the subexpression that disagrees, failing the build.
What this error means
dotnet build fails with "error FS0001: This expression was expected to have type X but here has type Y".
F#
Program.fs(7,18): error FS0001: This expression was expected to have type
'string'
but here has type
'int'Common causes
A value of the wrong type is supplied
The expression is one type (here int) but the context needs another (string); F# does not convert numeric and string types implicitly.
Inference fixed a type earlier than intended
An earlier use constrained a binding to a type that conflicts with a later use, so FS0001 fires at the second site.
How to fix it
Convert or annotate the value
- Read the expected versus actual type in the message.
- Insert the right conversion (for example
string n) or add a type annotation. - Re-run
dotnet build.
Program.fs
let label = "id-" + string nAdd annotations to steer inference
Annotate the parameter or binding so inference fixes the intended type rather than one implied by an earlier use.
Program.fs
let format (n: int) : string = string nHow to prevent it
- Annotate public function signatures so inference is predictable.
- Build locally before pushing to catch FS0001 early.
- Convert between types explicitly; F# avoids implicit coercion.
Related guides
F# "error FS0039: ... is not defined" in CIFix F# "error FS0039: The value or constructor X is not defined" in CI - the name is not in scope, usually a…
F# "error FS0078: Unable to find the file" in CIFix F# "error FS0078: Unable to find the file X in any of the following ..." in CI - an #load or #r directive…
dune "Error: This expression has type" in CIFix dune "Error: This expression has type X but an expression was expected of type Y" in CI - the OCaml type…