Skip to content
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

Generics in functions #974

Closed
paztis opened this issue Oct 27, 2014 · 3 comments
Closed

Generics in functions #974

paztis opened this issue Oct 27, 2014 · 3 comments
Labels
Fixed A PR has been merged for this issue

Comments

@paztis
Copy link

paztis commented Oct 27, 2014

I used to use generics in Java to define constraints between the different arguments of a function.
In TypeScript, they are a little more limited.
For example:

function test(a: T, b: T): void {
}
test(1, 2); //It works with T as number
test("a", 2); //It works with T as {}
test("a", 2); //Error "a" is not a number

I wish I did not have to specify the "number" type as we can do in Java.
For me test("a", 2) should cause an error. Compiler inference should not find {} as common type.

@danquirk
Copy link
Member

Good news, we agree and the latest bits do make this an error. See #868

@danquirk danquirk added the Fixed A PR has been merged for this issue label Oct 27, 2014
@paztis
Copy link
Author

paztis commented Oct 27, 2014

Great.
When is this version be available?

@danquirk
Copy link
Member

You can use the latest bits in master right now. For a Visual Studio release this will be in 1.4, unfortunately we can't share a date right now but you can track the progress here:

https://github.com/Microsoft/TypeScript/milestones

See also http://blogs.msdn.com/b/typescript/archive/2014/10/22/typescript-and-the-road-to-2-0.aspx

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants