diff --git a/test/forEach.test.ts b/test/forEach.test.ts index 3913897..41ffa58 100644 --- a/test/forEach.test.ts +++ b/test/forEach.test.ts @@ -14,3 +14,8 @@ expectType(forEach(__, arrRO)(noop)); expectType(forEach(noop)(arr)); expectType(forEach(noop)(arrRO)); + +// inline arrow functions should get type inferred +let someMutVar: number; +expectType(forEach(num => { someMutVar + num; }, arr)); +expectType(forEach(num => { someMutVar + num; }, arrRO)); diff --git a/types/forEach.d.ts b/types/forEach.d.ts index aa291a3..5065e86 100644 --- a/types/forEach.d.ts +++ b/types/forEach.d.ts @@ -1,5 +1,7 @@ import { Placeholder } from './util/tools'; export function forEach(fn: (x: T) => void): (list: U) => U; -export function forEach(__: Placeholder, list: U): (fn: (x: U extends readonly (infer T)[] ? T : never) => void) => U; -export function forEach(fn: (x: T) => void, list: U): U; +export function forEach(__: Placeholder, list: U): (fn: (x: U extends readonly (infer T)[] ? T : never) => void) => U; +export function forEach(fn: (x: U extends readonly (infer T)[] ? T : never) => void, list: U): U; +// this last one is for addIndex(forEach) +export function forEach(fn: (item: T) => void, list: readonly T[]): T[];