Expose the encoded type from TestSchema.Encoding.encodeUnknownEffect - #6937
Expose the encoded type from TestSchema.Encoding.encodeUnknownEffect#6937fubhy wants to merge 1 commit into
Conversation
|
There was a problem hiding this comment.
Important
This PR currently adds only the failing reproduction test. The one-line implementation fix is still missing from packages/effect/src/testing/TestSchema.ts.
Reviewed changes
- Adds a TSTyche type test in
packages/effect/typetest/TestSchema.tst.tsthat assertsEncoding.encodeUnknownEffectforSchema.NumberFromStringproducesEffect<string, SchemaIssue.Issue>.
I ran the targeted type test and confirmed it fails as expected before the fix: the current type is Effect<number, Issue, never> because TestSchema.Encoding.encodeUnknownEffect is declared with S["Type"] instead of S["Encoded"].
⚠️ Implementation fix not yet included
The root cause is outside this diff, so it cannot be resolved by editing the test file alone. In packages/effect/src/testing/TestSchema.ts, the encodeUnknownEffect field is annotated as Effect.Effect<S["Type"], ...>, while the SchemaParser.encodeUnknownEffect call assigned to it returns Effect.Effect<S["Encoded"], ...>. Update the annotation to S["Encoded"] so the public type matches the runtime value.
Technical details
# Fix the `Encoding.encodeUnknownEffect` return type
## Affected sites
- `packages/effect/src/testing/TestSchema.ts:462` — `encodeUnknownEffect` uses `S["Type"]` instead of `S["Encoded"]`
- `packages/effect/typetest/TestSchema.tst.ts:10` — regression test that verifies `Effect<string, SchemaIssue.Issue>` for `NumberFromString`
## Required outcome
- `TestSchema.Encoding.encodeUnknownEffect` is typed as `Effect.Effect<S["Encoded"], SchemaIssue.Issue, S["EncodingServices"]>`.
- `pnpm test-types packages/effect/typetest/TestSchema.tst.ts` passes.
## Suggested approach
In `packages/effect/src/testing/TestSchema.ts`, change line 462 from:
```ts
) => Effect.Effect<S["Type"], SchemaIssue.Issue, S["EncodingServices"]>
```
to:
```ts
) => Effect.Effect<S["Encoded"], SchemaIssue.Issue, S["EncodingServices"]>
```
## Follow-ups
- Add a `.changeset` entry because this corrects an exported public API type.
- Run `pnpm lint`, `pnpm check`, and `pnpm test-types packages/effect/typetest/TestSchema.tst.ts` after applying the fix.@v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏
| it("types Encoding.encodeUnknownEffect with the encoded output", () => { | ||
| const encoding = new TestSchema.Asserts(Schema.NumberFromString).encoding() | ||
|
|
||
| expect(encoding.encodeUnknownEffect(1)).type.toBe<Effect.Effect<string, SchemaIssue.Issue>>() |
There was a problem hiding this comment.
This assertion is the correct regression spec. It currently fails because TestSchema.Encoding.encodeUnknownEffect is still declared with S["Type"] in packages/effect/src/testing/TestSchema.ts:462; once that annotation is corrected to S["Encoded"], this test should pass.

Summary
TestSchema.Encoding.encodeUnknownEffect is typed as succeeding with the decoded Type even though it returns the Encoded value.
Important
This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.
Encoding.encodeUnknownEffect exposes the decoded type
Module:
TestSchemaAudit ID:
core-s-z-testing-test-schema-encoded-typeSeverity / confidence: medium / high
What happens
TestSchema.Encoding.encodeUnknownEffect is typed as succeeding with the decoded Type even though it returns the Encoded value.
Why it happens
The public property is annotated as Effect.Effect<S["Type"], ...> even though SchemaParser.encodeUnknownEffect returns Effect.Effect<S["Encoded"], ...>, breaking type-safe composition for transformed schemas.
Expected behavior
An encoding operation succeeds with the schema's Encoded type.
Relevant implementation
These links and excerpts are pinned to audit base
c9b56ab507f224426ee8388dc450da447ec4715f.packages/effect/src/testing/TestSchema.ts:457-470packages/effect/src/SchemaParser.ts:600-610View problematic code at
packages/effect/src/testing/TestSchema.ts:457-470View exact lines on GitHub
View problematic code at
packages/effect/src/SchemaParser.ts:600-610View exact lines on GitHub
Reproduction
Observed failure: TypeScript 5.9.3 and 6.0.3 report Effect<number, Issue> is not Effect<string, Issue>
Implementation handoff
The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.
Audit provenance
c9b56ab507f224426ee8388dc450da447ec4715fc9b56ab507f224426ee8388dc450da447ec4715fcore-s-z-testing-test-schema-encoded-type