Skip to content

proposal: Allow type inference from return signature #73068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
falco467 opened this issue Mar 27, 2025 · 1 comment
Closed

proposal: Allow type inference from return signature #73068

falco467 opened this issue Mar 27, 2025 · 1 comment
Labels
LanguageProposal Issues describing a requested change to the Go language specification. Proposal
Milestone

Comments

@falco467
Copy link

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.

@gopherbot gopherbot added this to the Proposal milestone Mar 27, 2025
@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the LanguageProposal Issues describing a requested change to the Go language specification. label Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LanguageProposal Issues describing a requested change to the Go language specification. Proposal
Projects
None yet
Development

No branches or pull requests

4 participants