Skip to content

Instantly share code, notes, and snippets.

@thomasboyt
Created April 8, 2016 08:12
Show Gist options
  • Save thomasboyt/948dd82ca870307839531952c54c6436 to your computer and use it in GitHub Desktop.
Save thomasboyt/948dd82ca870307839531952c54c6436 to your computer and use it in GitHub Desktop.
const arr = <any>[1,2,3];
// why does typescript think sum is `any` instead of `num`? shouldn't it use the type of
// initialValue here?
const arrSum = arr.reduce((acc, val) => acc + val, 0); // arrSum is `any`
// ImmutableJS does this correctly:
import I from 'immutable';
const list = I.List<any>().push(1).push(2).push(3);
const listSum = list.reduce((acc, val) => acc + val, 0); // listSum is `number`
@thomasboyt
Copy link
Author

looks like this is the culprit: microsoft/TypeScript#7014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment