Standard library / go/types

go/types.AssertableTo()

Reports whether a value of an ordinary interface type can be asserted to the target type. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func AssertableTo(V *Interface, T Type) bool

Parameters & Attributes

NameTypeDescription
V*InterfaceSource or candidate type.
TTypeDestination type or interface, or type to inspect.

Return Value

bool

Reports whether a value of an ordinary interface type can be asserted to the target type.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() {  fmt.Println(types.AssertableTo(types.NewInterfaceType(nil, nil).Complete(), types.Typ[types.Int]))}
Go Reference