Skip to content

proposal: Allow type inference from return signature #73068

Closed as duplicate of#50285
@falco467

Description

@falco467

Proposal Details

Take the following example. I think the compiler should be able to infer T=string.

func generic[T any]() (t T) {
	return
}

func hello() string {
	return generic() // Currently Error: Cannot infer T
}

Other languages like TypeScript and Java will infer the type-argument by the return signature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LanguageProposalIssues describing a requested change to the Go language specification.Proposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions