Skip to content

Generic methods are not properly inferred when used as a value #5251

@david-driscoll

Description

@david-driscoll

I think I have noticed a problem with Generic Methods, not properly inferring their types, when they are used as a value, instead of as a method. I'm not sure if it's a known issue or not.

It's easy enough to work around by using a function, but I'd prefer to just hand in the method, since it's already a method that can be called.

This case is in Rx, but I've seen other examples of it too.

var observableOfAny = Observable.from(items)
    .flatMap(Observable.from); // using as a variable doesn't work

var observableOfString = Observable.from(items)
    .flatMap(x => Observable.from(x)); // Using a delegate works

var fromString: (arr: string[]) => Observable<string> = Observable.from;
var observableOfString = Observable.from(items)
    .flatMap(fromString); // Properly casting the method works

I've got an example, again using rx interfaces (so maybe something is wrong with them? it's possible). playground example

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions