From 8fed390b03377606e8709321aabba6bb08a26472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ole=C5=9B?= Date: Wed, 17 Apr 2019 15:34:48 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Make=20`composeDetectors?= =?UTF-8?q?`=20less=20type=20strict?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed `TAction = any` generic type from `composeDetectors` function because typescript type inheritance makes wrong assumptions about TAction type if you compose detectors with different TAction type. --- src/composeDetectors.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/composeDetectors.ts b/src/composeDetectors.ts index 414d2ef..68edc22 100644 --- a/src/composeDetectors.ts +++ b/src/composeDetectors.ts @@ -3,9 +3,9 @@ import { ActionsDetector } from "./Detector"; /** * Compose many action detectors into one detector that aggregates actions returned by given detectors */ -export function composeDetectors( - ...detectors: ActionsDetector[] -): ActionsDetector { +export function composeDetectors( + ...detectors: ActionsDetector[] +): ActionsDetector { // check detectors types in runtime const invalidDetectorsIndexes: number[] = detectors .map((detector, index) => (detector instanceof Function ? -1 : index)) @@ -29,9 +29,6 @@ export function composeDetectors( ): any[] { return detectors .map(detector => detector(prevState, nextState) || []) - .reduce( - (actions: TAction[], nextActions) => actions.concat(nextActions), - [] - ); + .reduce((actions: any[], nextActions) => actions.concat(nextActions), []); }; }