Skip to content
Latchkey

Go "cannot use X (variable of type A) as B value" - Fix in CI

Go is statically typed and never implicitly converts between types. Passing a value whose type does not match the parameter is a compile error.

What this error means

A build fails with cannot use x (variable of type A) as B value in argument to f. It commonly follows a signature change or a refactor that altered a value type.

go
./api.go:21:14: cannot use id (variable of type int64) as string value in argument to lookup

Common causes

Signature changed

A parameter type changed but a caller still passes the old type.

Missing explicit conversion

Go requires an explicit conversion between numeric or named types; the call omitted it.

How to fix it

Convert the value explicitly

  1. Wrap the argument in the target conversion, or fix the caller to pass the right type.
Go
lookup(strconv.FormatInt(id, 10))

Align callers with the signature

  1. Update every call site after changing a function signature, then rebuild.
Terminal
go build ./...

How to prevent it

  • Update all call sites when you change a signature.
  • Build locally before pushing to catch type mismatches.
  • Prefer explicit conversions over relying on inference.

Frequently asked questions

What causes ""cannot use X as type""?
A parameter type changed but a caller still passes the old type.
How do I fix "cannot use X as type"?
Convert the value explicitly

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card