From 2330349ad62ebca39a64d961036a557b7f702e5b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 24 Mar 2023 22:33:12 -0500 Subject: [PATCH] Fix types... Jesus --- src/pipeline.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pipeline.ts b/src/pipeline.ts index ff0469e..650eafe 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -1,7 +1,9 @@ import { InputMessage, OutputMessage, Policy } from './types.ts'; /** A policy function with opts to run it with. Used by the pipeline. */ -type PolicyTuple = [policy: Policy, opts?: Opts]; +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. */ // https://stackoverflow.com/a/75806165 @@ -28,7 +30,7 @@ async function pipeline(msg: InputMessage, policies: [...Policy } /** Coerce item into a tuple if it isn't already. */ -function toTuple(item: PolicyTuple | Policy): PolicyTuple { +function toTuple

(item: PolicyTuple

| P): PolicyTuple

{ return typeof item === 'function' ? [item] : item; }