Standard library / go/types
go/types.Alias.SetTypeParams()
Sets the type parameters of an uninstantiated alias. This API alone does not establish language support for generic aliases. Expected stdout: '1\n'.
Formal Syntax & Structure
go syntaxgo
func (a *Alias) SetTypeParams(tparams []*TypeParam)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| tparams | []*TypeParam | Input to the operation as described above. |
Working Example
Example Snippetgo
package main
import ( "fmt" "go/types")
func main() { v := types.NewAlias(types.NewTypeName(0, nil, "A", nil), types.Typ[types.Int]) p := types.NewTypeParam(types.NewTypeName(0, nil, "T", nil), types.Universe.Lookup("any").Type()) v.SetTypeParams([]*types.TypeParam{p}) fmt.Println(v.TypeParams().Len())}