-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Bad type inference from return type #16099
Comments
You have to provide some information for TS to infer types, otherwise it wouldn't know what for example // <ItemType extends string>
declare function flatMap<ItemType extends string, ProjectedItemType>(projectorFn: (item: ItemType) => ProjectedItemType[]): (aggregate: ProjectedItemType[], item: ItemType) => ProjectedItemType[];
['alice', 'bob'].reduce(flatMap(name => name.split('')), []); or // (name: string) => name.split('')
declare function flatMap<ItemType, ProjectedItemType>(projectorFn: (item: ItemType) => ProjectedItemType[]): (aggregate: ProjectedItemType[], item: ItemType) => ProjectedItemType[];
['alice', 'bob'].reduce(flatMap((name: string) => name.split('')), []); |
@ikatyang I know, but it would be nice if compiler could work out type of name from return type. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Code
Expected behavior:
TypeScript compiler should infer that type of
name
isstring
.Actual behavior:
Compiler error:
Property 'split' does not exist on type '{}'.
The text was updated successfully, but these errors were encountered: