Function overloads no longer support generics on the implementation signature?

Topics: General, Language Specification
Dec 7, 2013 at 1:03 PM
Edited Dec 7, 2013 at 1:05 PM
Works:
    foo<T>(): T;
    foo<T>(x: string): T;
    foo<T>(x: Date): T;
    foo(x?: any): any {
        return null;
    }
Does not work:
    foo<T>(): T;
    foo<T>(x: string): T;
    foo<T>(x: Date): T;
    foo<T>(x?: any): T {
        return null;
    }
This used to work in 0.9.1.1. This is a problem when the function implementation needs to make a call to another function using the generic argument. Or is the suggestion to simply pass <any> in that case?

EDIT
I suppose that might make sense actually, seeing as you can't directly call the implementation signature, and because generics are compile-time constructs only, and therefore non-reflectable, it would serve no purpose to place them on the implementation signature.
Dec 8, 2013 at 11:33 AM
I had a similar issue. See https://typescript.codeplex.com/workitem/1918

Although your case is different because you are not really specialising the return value.

The specialised overload signatures can be claimed to be a subtype of the non-specialised signature hence shouldn't be an error.