From c6c7b759e67727e8c358f0fbfd49b5928b3811cc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 25 Mar 2023 08:24:47 -0500 Subject: [PATCH] Type tweaks --- src/pipeline.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index 650eafe..dc0e62d 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -5,16 +5,16 @@ type PolicyTuple

= [policy: P, opts?: InferPolicyOpts /** Infer opts from the policy. */ type InferPolicyOpts

= P extends Policy ? Opts : never; -/** Helper type for proper type inference of PolicyTuples in the pipeline. */ +/** Helper type for proper type inference of PolicyTuples. */ // https://stackoverflow.com/a/75806165 // https://stackoverflow.com/a/54608401 -type PolicySpread = { +type Policies = { [K in keyof T]: PolicyTuple | Policy; }; /** Processes messages through multiple policies, bailing early on rejection. */ -async function pipeline(msg: InputMessage, policies: [...PolicySpread]): Promise { - for (const item of policies) { +async function pipeline(msg: InputMessage, policies: [...Policies]): Promise { + for (const item of policies as (Policy | PolicyTuple)[]) { const [policy, opts] = toTuple(item); const result = await policy(msg, opts); if (result.action !== 'accept') {