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.
./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
- Read the expected type at the named call site.
- Adapt the argument (convert, wrap, or construct the expected type) or implement the missing interface method.
- 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.
var _ Store = (*MemStore)(nil) // fails to compile if Store isn't satisfiedHow to prevent it
- Pin dependencies and read changelogs before upgrading.
- Add
var _ Iface = (*T)(nil)assertions for important interfaces. - Run
go build ./...andgo vet ./...before merging.