A type alias in Go gives an existing type a second name using type Alias = Existing. The alias and the original are the same type, so values are fully interchangeable with no conversion. This is different from a defined type, type Celsius float64, which creates a new, distinct type.
Aliases exist mainly for gradual refactoring and moving types between packages. Use a defined type when you want a new name with its own methods and type safety.
The only syntactic difference is the equals sign.
%T prints float64 for the alias because the compiler treats Temp and float64 as identical. For Celsius, you need a conversion, and you can attach methods to it.
| Feature | Defined type (type A B) | Alias (type A = B) |
|---|---|---|
| New distinct type | Yes | No, same type |
Implicit assignment from B | No | Yes |
Can declare methods on A | Yes (same package) | Only if B allows it |
| Method set | Does not inherit B's methods | Same as B |
| Typical use | Domain types, enums, safety | Refactoring, shorter names |
Aliases arrived in Go 1.9. The motivation was large-scale code repair: if you move a type from package old to package new, every user would otherwise have to change at once. With an alias, you leave a forwarding name behind.
Code that uses old.Client keeps compiling and refers to exactly the same type as newpkg.Client, so values pass between old and new code freely. Because they are one type, type switches, interface satisfaction and reflect all see a single type.
Two aliases of the same name are also common in the standard library. any is an alias for interface{} and byte is an alias for uint8; rune is an alias for int32. A defined type would break compatibility there.
You can also shorten or document an awkward type.
This helps with long signatures, but remember that an alias adds no safety: a Registry is still just a map[string][]func(string) error everywhere. If you want the compiler to stop callers from mixing values, define a new type.
Alias declarations can take type parameters. This was available as an opt-in experiment in Go 1.23 and is enabled by default from Go 1.24.
Before Go 1.24, you could alias an instantiated generic type such as type IntSlice = []int, but not declare a generic alias. Check your go directive in go.mod if you hit a compile error.
You cannot add methods to an alias of a type from another package, because methods must be declared in the package that defines the type.
You can, however, call all of time.Time's methods through MyTime. To add behaviour you need a defined type, for example type MyTime time.Time (which loses time.Time's methods) or a struct that embeds it.
UserID, Celsius or Status, where mixing values is a bug and you want to hang methods on the type.type ID = int documents nothing the compiler can enforce.byte and uint8 the same type?Yes. byte is an alias for uint8, and rune is an alias for int32, so you can use them interchangeably without conversion.
An alias has the method set of its target, so it satisfies exactly the interfaces the target satisfies. It cannot add new methods.
No. reflect.TypeOf returns the same reflect.Type for an alias and the original type, and error messages show the original name.
No. Use a defined type such as type Status int with constants. Aliases are interchangeable with the base type, so the compiler cannot catch mix-ups.
type A = B makes A another name for B, with identical behaviour, while type A B creates a new type. Aliases are for refactoring, compatibility and shorter spellings, and since Go 1.24 they can be generic. For type safety and methods, define a new type instead.