Standard library / go/types

go/types.NewTypeName()

Creates a type-name object; passing nil allows a subsequently constructed defined type to associate itself with the object. Expected stdout: 'Count true\n'.

Formal Syntax & Structure

go syntaxgo
func NewTypeName(pos token.Pos, pkg *Package, name string, typ Type) *TypeName

Parameters & Attributes

NameTypeDescription
postoken.PosSource position in the associated file set.
pkg*PackagePackage containing the symbol; nil for package-independent objects.
namestringName of the symbol or package.
typTypeType associated with the object or value.

Return Value

*TypeName

Creates a type-name object; passing nil allows a subsequently constructed defined type to associate itself with the object.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() { o := types.NewTypeName(0, nil, "Count", nil); fmt.Println(o.Name(), o.Type() == nil) }
Go Reference