ts-pattern should be a peerDependency, not an exact pinned dependency
Summary
unthrown@5 declares ts-pattern as an exact, plain dependency:
"dependencies": { "ts-pattern": "5.9.0" }
Any consumer that already uses ts-pattern at a different version therefore ends up with two
copies whose declarations do not unify, and mixing them is a type error.
Reproduction
Consumer has [email protected] (~72 files use it directly). Install [email protected].
pnpm nests a second [email protected] under unthrown. Then:
import { P } from "ts-pattern"; // our copy, 5.7.0
import { tag } from "unthrown"; // built against unthrown's copy, 5.9.0
result.recoverErrCases((matcher) =>
matcher.with(P.union(tag("A"), tag("B")), handler),
);
Argument of type 'Chainable<OrP<unknown, readonly [{ _tag: "A"; }, { _tag: "B"; }]>>'
is not assignable to parameter of type 'KnownPattern<AError | BError>'.
Impact
The workaround — always import P / match / tag from "unthrown" when the pattern feeds an
unthrown matcher — works, and we adopted it. But it is a footgun: import { P } from "ts-pattern"
is the obvious thing to write, the failure surfaces five layers deep in a conditional type, and
nothing in the error hints that two copies of the library are involved.
Simply aligning our catalog to 5.9.0 to force dedupe was not an option in the same change:
ts-pattern 5.8 tightened exhaustiveness on optional discriminants, which breaks any match over
a union whose discriminant property is optional — a shape code generators emit routinely. That put
several unrelated call sites in other parts of the repo in scope. So the consumer is forced either
into a wide, unrelated refactor or into the two-copies workaround.
Suggested fix
"peerDependencies": { "ts-pattern": "^5" },
"devDependencies": { "ts-pattern": "5.9.0" }
That lets the consumer own the version, guarantees a single copy, and makes
import { P } from "ts-pattern" work exactly as a user would expect. If a specific floor is
needed, "^5.9" is still far better than an exact pin.
Environment
[email protected], pnpm 11.1.2 workspace with a version catalog