Skip to content

proposal: reflect: add Value.TypeAssert[T any] #78008

Description

@mateusz834

Proposal Details

Assumes #77273

With generic methods, we can make TypeAssert easier to use.

Proposal:

// TypeAssert is semantically equivalent to:
//
//	v2, ok := v.Interface().(T)
func (v Value) TypeAssert[T any] (v2 T, ok bool)

And we can mark the normal TypeAssert with go:fix inline:

//go:fix inline
func TypeAssert[T any](v Value) (T,  bool) {
        return v.TypeAssert[T]()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions