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) *AliasParameters & Attributes
| Name | Type | Description |
|---|---|---|
| obj | *TypeName | Object associated with the type or scope. |
| rhs | Type | Input 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]))}