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) *TypeParamParameters & Attributes
| Name | Type | Description |
|---|---|---|
| obj | *TypeName | Object associated with the type or scope. |
| constraint | Type | Type 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())}