10000 Bad type inference from return type · Issue #16099 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
Bad type inference from return type #16099
Closed
@dawidgarus

Description

@dawidgarus

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)

Code

function flatMap<ItemType, ProjectedItemType>(projectorFn: (item: ItemType) => ProjectedItemType[]): (aggregate: ProjectedItemType[], item: ItemType) => ProjectedItemType[] {
	return (aggregate: ProjectedItemType[], current: ItemType) => aggregate.concat(projectorFn(current) || []);
}

['alice', 'bob'].reduce(flatMap(name => name.split('')), []);
['alice', 'bob'].reduce(flatMap<string, string>(name => name.split('')), []); // this works fine

Expected behavior:
TypeScript compiler should infer that type of name is string.

Actual behavior:
Compiler error: Property 'split' does not exist on type '{}'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    31B9 Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0