The sole purpose of callbacks to exist here in IloopCallbacks, separately from ILoopOptions, is due to a Zen/TypeScript limitation, that doesn't properly infer the type of a callback's arguments (it ignores the options, probably cause they belong to same type interface before it has been initialized).
So, in order to have perfect automatic inference of args, callbacks have to be in a separate 3rd argument in loop() parameters, loop(input, options, callbacks) eg
The sole purpose of callbacks to exist here in
IloopCallbacks
, separately fromILoopOptions
, is due to a Zen/TypeScript limitation, that doesn't properly infer the type of a callback's arguments (it ignores the options, probably cause they belong to same type interface before it has been initialized).So, in order to have perfect automatic inference of args, callbacks have to be in a separate 3rd argument in
loop()
parameters,loop(input, options, callbacks)
egloop(input, {props: true}, { map: (val, prop) => val *2 })
instead of the desired (but type-breaking)
loop(input, {props: true, map: (val, prop) => val *2 })
// BREAKS TypeScript type inference of callback argsImplementation-wise & at runtime, the 2 are equivalent
See
ILoopOptions