Skip to content

Match.tagsExhaustive and other record combinators reject a Match.fn matcher and drop its arguments #10874

In review

Description

@jasonkuhrt

Written by an AI agent (Amp) on behalf of @jasonkuhrt.

What version of Effect is running?

effect 4.1.5, the latest release, and main at 0d2bb4a.

What steps can reproduce the bug?

A Match.fn matcher can't use Match.tagsExhaustive, Match.tags or the other record and discriminator combinators with the selector's arguments. The types reject the matcher, and at run time tagsExhaustive's handler gets the narrowed value alone.

npm init -y && npm pkg set type=module
npm install --save-exact [email protected] [email protected]
echo '{ "compilerOptions": { "strict": true, "module": "nodenext", "target": "es2022", "noEmit": true, "allowImportingTsExtensions": true }, "files": ["repro.ts"] }' > tsconfig.json
// repro.ts
import { Match } from "effect"

type Event = { readonly _tag: "Opened" } | { readonly _tag: "Closed" }

const describe = Match.fn((_prefix: string, event: Event) => event).pipe(
  Match.tag("Opened", (_event, prefix) => `${prefix} opened`),
  Match.tagsExhaustive({ Closed: (_event, prefix) => `${prefix} closed` })
)

console.log(describe("door", { _tag: "Opened" }))
console.log(describe("door", { _tag: "Closed" }))
npx tsc -p .
node repro.ts # Node 24.22.3

What is the expected behavior?

tsc reports no errors, and the script prints:

door opened
door closed

Match.fn's description in #7363 is to "carry selector arguments through handler combinators and terminal return types". Match.tag does this.

What do you see instead?

tsc exits 1 (output cut to the first two errors):

repro.ts(8,3): error TS2345: Argument of type '<I, F, A, Pr>(self: Matcher<I, F, { readonly _tag: "Closed"; }, A, Pr, any, []>) => …' is not assignable to parameter of type '(_: Matcher<Event, Without<{ readonly _tag: "Opened"; }>, { readonly _tag: "Closed"; }, string, never, any, [_prefix: string, event: Event]>) => (u: Event) => any'.
  …
          Type '[]' is not assignable to type '[_prefix: string, event: Event]'.
repro.ts(8,26): error TS2322: Type '(_event: any, prefix: any) => string' is not assignable to type '(_: { readonly _tag: "Closed"; }) => any'.
  Target signature provides too few arguments. Expected 2 or more, but got 1.

and the script prints:

door opened
undefined closed

Additional information

#7363 threads Args through when, whenOr, whenAnd, not, tag, orElse and the terminals. The other combinators take self: Matcher<I, F, R, A, Pr, Ret>, whose Args defaults to []:

Combinators Types accept a Match.fn matcher Handler gets the arguments at run time
when, whenOr, whenAnd, not, tag yes yes
discriminator, discriminatorStartsWith, tagStartsWith no yes
tags, tagsExhaustive, discriminators, discriminatorsExhaustive, literals, literalsExhaustive no no

Activity

  1. self-assigned this
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions