Standard library / go/types

go/types.NewTypeParam()

Creates a type parameter with an associated type name and constraint. Expected stdout: 'T any\n'.

Formal Syntax & Structure

go syntaxgo
func NewTypeParam(obj *TypeName, constraint Type) *TypeParam

Parameters & Attributes

NameTypeDescription
obj*TypeNameObject associated with the type or scope.
constraintTypeType constraint for the parameter.

Return Value

*TypeParam

Creates a type parameter with an associated type name and constraint.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  p := types.NewTypeParam(types.NewTypeName(0, nil, "T", nil), types.Universe.Lookup("any").Type())  fmt.Println(p.Obj().Name(), p.Constraint())}
Go Reference