diff --git a/src/tagged-union.ts b/src/tagged-union.ts index 26b0a00..69aa65b 100644 --- a/src/tagged-union.ts +++ b/src/tagged-union.ts @@ -99,6 +99,17 @@ interface TaggedUnionMatcherWidening { ): UnaryFn | R>; } +// The key-taking step of the curried factory. Naming it lets the factory return +// `dispatch` directly, the tacit twin of the primitive-union factory's bare +// `=> dispatch`. +interface TaggedUnionMatcherFactory { + >(k: K): TaggedUnionMatcherStrict; +} + +interface TaggedUnionMatcherWideningFactory { + >(k: K): TaggedUnionMatcherWidening; +} + const dispatch = (k: PropertyKey) => (handlers: HandlerMap, fallback?: UnaryFn) => @@ -120,12 +131,10 @@ const dispatch = ); }; -export const getTaggedUnionMatcher = - () => - >(k: K): TaggedUnionMatcherStrict => - dispatch(k); +export const getTaggedUnionMatcher = < + T extends object, +>(): TaggedUnionMatcherFactory => dispatch; -export const getTaggedUnionMatcherW = - () => - >(k: K): TaggedUnionMatcherWidening => - dispatch(k); +export const getTaggedUnionMatcherW = < + T extends object, +>(): TaggedUnionMatcherWideningFactory => dispatch;