Skip to content
Latchkey

Go "cannot use ... as ... in argument" - Fix Type Mismatch in CI

The Go type checker rejected an assignment or call because the value’s type does not match what was expected. Often a dependency upgrade changed a signature, or a type no longer satisfies an interface.

What this error means

Compilation fails with cannot use x (variable of type A) as type B in argument or does not implement <Interface> (missing method M), pointing at an exact call site. It is a deterministic type error.

go build output
./handler.go:21:14: cannot use cfg (variable of type *Config) as
type Options in argument to New

./store.go:9:10: *MemStore does not implement Store (missing method Close)

Common causes

A dependency changed a function signature

An upgraded module altered a parameter or return type, so your existing call no longer type-checks against the new API.

A type no longer satisfies an interface

An interface gained a method, or your type’s method set drifted, so it no longer implements the interface the call requires.

How to fix it

Reconcile with the new signature

  1. Read the expected type at the named call site.
  2. Adapt the argument (convert, wrap, or construct the expected type) or implement the missing interface method.
  3. If you cannot migrate yet, pin the dependency to the prior version.

Confirm the interface is fully implemented

Add a compile-time assertion so a missing method fails clearly and early.

store.go
var _ Store = (*MemStore)(nil)   // fails to compile if Store isn't satisfied

How to prevent it

  • Pin dependencies and read changelogs before upgrading.
  • Add var _ Iface = (*T)(nil) assertions for important interfaces.
  • Run go build ./... and go vet ./... before merging.

Frequently asked questions

What causes ""cannot use X as Y""?
An upgraded module altered a parameter or return type, so your existing call no longer type-checks against the new API.
How do I fix "cannot use X as Y"?
Reconcile with the new signature

Related guides

References

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