Standard library / go/types

go/types.NewAlias()

Creates an alias whose right-hand side is the supplied type. Aliases do not create distinct type identity. Expected stdout: 'Count true\n'.

Formal Syntax & Structure

go syntaxgo
func NewAlias(obj *TypeName, rhs Type) *Alias

Parameters & Attributes

NameTypeDescription
obj*TypeNameObject associated with the type or scope.
rhsTypeInput to the operation as described above.

Return Value

*Alias

Creates an alias whose right-hand side is the supplied type.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  o := types.NewTypeName(0, nil, "Count", nil)  a := types.NewAlias(o, types.Typ[types.Int])  fmt.Println(a, types.Identical(a, types.Typ[types.Int]))}
Go Reference