What is the difference between a nil interface and an interface holding a nil pointer (the 'typed nil' pitfall)?

Last updated 20 June 2026

  • A nil interface has both type and data words nil. A "typed nil" holds a concrete type (e.g. *T) with a nil pointer, so it is NOT equal to nil.

  • Common trigger: returning a nil *MyErr from a function whose return type is error, making err != nil true.

  • Fix: return a literal nil for the interface, or check the concrete pointer before wrapping it.

  • https://dev.to/gabrielanhaia/the-strange-case-of-gos-nil-interface-comparison-2deh
All Golang interview questions