cannot use x as type in assignment/argument Go Origin: Application & API Last updated 4 Nov 2026

Go: cannot use "5" (untyped string constant) as int value in argument to f

A value's type is not assignable to the type required by the variable, parameter or return value.

Exact message you may see cannot use "5" (untyped string constant) as int value in argumentcannot use x (variable of type int) as string value in assignmentcannot use v (variable of type []string) as []interface{} valuecannot use &x (value of type *T) as T value
Seen on: Go

Meaning

The message gives both types. Common cases: a string where an int is needed, []T vs []interface{}, a value vs pointer, or an interface not satisfied. Convert, take the address (&v), or change the declared type.

Common causes

  • String vs int mix-up
  • Value passed where pointer expected (or reverse)
  • []string passed as []interface{}
  • Missing interface method
  • Untyped constant overflows the type

⚡ Quick fix

  1. Convert with strconv.Itoa / strconv.Atoi or a type conversion
  2. Pass &v or *p as required
  3. Build a new []any by looping

Detailed fix by platform

Go

  1. n, err := strconv.Atoi("5") for string to int

How to diagnose

  1. Types — Required vs given?
  2. Pointer — & or * needed?
  3. Slice — Element type same?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

assignment mismatch: 1 variable but f returns 2 values — Go: assignment mismatch: 1 variable but os.Open returns 2 values (Go)assignment mismatch: …cannot assign to struct field m[k].f in map — Go: cannot assign to struct field users["bob"].Age in map (Go)cannot assign to stru…cannot refer to unexported name — Go: cannot refer to unexported name pkg.helper (undefined: pkg.helper) (Go)cannot refer to unexp…does not implement interface (missing method) — Go: cannot use &Dog{} (value of type *Dog) as Animal value: *Dog does not implement Animal (missing method Speak) (Go)does not implement in…E0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308function main is undeclared in the main package — Go: runtime.main_main·f: function main is undeclared in the main package (Go)function main is unde…import cycle not allowed — Go: package app/models imports app/utils imports app/models: import cycle not allowed (Go)import cycle not allo…imported and not used — Go: ./main.go:5:2: "os" imported and not used (Go)imported and not usedcannot us…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.