Skip to content

proposal: generic should infer type from variable definition #50285

Open
@LeGamerDc

Description

@LeGamerDc

hope go could support infer generic type from variable type

func main() {
	var x Person = get() // to replace var x = get[Person]()
	fmt.Println(x)
}

func get[T any]() T {
	var x T
	return x
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Hold

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions