From 6b286db51a69c0cc78ba9801e403240d4c49c3d9 Mon Sep 17 00:00:00 2001 From: Ibby Date: Wed, 5 Oct 2016 23:19:45 -0400 Subject: [PATCH] chore(): add successIndex at the correct position if we have optional params --- src/plugins/plugin.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/plugin.ts b/src/plugins/plugin.ts index 23ea04ff6..7b0a744c5 100644 --- a/src/plugins/plugin.ts +++ b/src/plugins/plugin.ts @@ -61,7 +61,12 @@ function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Func args.push(obj); } else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') { // If we've specified a success/error index - args.splice(opts.successIndex, 0, resolve); + + if (opts.successIndex > args.length) { + args[opts.successIndex] = resolve; + } else { + args.splice(opts.successIndex, 0, resolve); + } // We don't want that the reject cb gets spliced into the position of an optional argument that has not been defined and thus causing non expected behaviour. if (opts.errorIndex > args.length) {