Prevent Effect.provideServiceEffect supertype widening - #7025
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — one suggestion to round out the new type test.
Reviewed changes
packages/effect/src/Effect.ts: addedNoInfer<S>to theacquireparameter of bothprovideServiceEffectoverloads so the acquisition effect can no longer widen the inferred service type.packages/effect/typetest/Effect.tst.ts: added a type-level regression test using a literal service type and@ts-expect-errorfor anEffect<string, never, never>acquisition..changeset/loose-wings-lie.md: added a patch changeset foreffect.
The fix is consistent with the existing Layer.effect overload, which already uses Types.NoInfer<S> for the same reason. I ran pnpm test-types packages/effect/typetest/Effect.tst.ts and the new test passes (206 tests, 314 assertions).
@v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
7c756f7 to
c024757
Compare
🦋 Changeset detectedLatest commit: c024757 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Added a data-first type test in
packages/effect/typetest/Effect.tst.tsto cover bothprovideServiceEffectoverloads, addressing the prior review feedback. - The
NoInfer<S>signature change inpackages/effect/src/Effect.tsand the patch changeset remain unchanged.
@v0 or keep the SHA fresh with Dependabot | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

Type
Description
Currently
Effect.provideServiceEffectacquire Effect is also used for inferring generic of provided service value. This makes returning supertype from Effect pass type checking. I discovered this in my own project where I've added new field to Context.Service and it didn't catch any issues despite it not being properly provided.To fix this I added NoInfer marker to acquire effect to make sure that it isn't constituting to inferred type. I added type level test, which correctly fails without this PR change:
Related
N/A