Type semantics

Underlying types

A defined type’s underlying type follows definitions to a predeclared type or type literal. Distinct defined types may share an underlying type without being identical or freely assignable. Example output: 'main.A main.B 3'.

Formal Syntax & Structure

go syntaxgo
type A int; type B A

Working Example

Example Snippetgo
package main
import "fmt"
type A inttype B A
func main() {  var x A = 3  var y B = B(x)  fmt.Printf("%T %T %d\n", x, y, y)}
Go Reference