Skip to content

Schema.Encoded strips Redacted wrapper when it should preserve it #5932

@SemStassen

Description

@SemStassen

What version of Effect is running?

3.19.3

What steps can reproduce the bug?

Problem

Schema.Encoded for Schema.Redacted returns the underlying encoded type (e.g., string) instead of preserving the Redacted wrapper (e.g., Redacted<string>).

Expected Behavior

According to RedactedFromSelf interface (line 6303), .Encoded should preserve Redacted:

redacted_.Redacted<Schema.Encoded<Value>>

Actual Behavior

Schema.Redacted is implemented as a transform (line 6332), and transform's .Encoded uses the input schema's encoded type (line 4121), which strips the Redacted wrapper.

Relevant Code Locations

1. RedactedFromSelf - Shows expected behavior

File: node_modules/effect/src/Schema.ts
Lines: 6299-6306

export interface RedactedFromSelf<Value extends Schema.Any> extends
  AnnotableDeclare<
    RedactedFromSelf<Value>,
    redacted_.Redacted<Schema.Type<Value>>,
    redacted_.Redacted<Schema.Encoded<Value>>,  // ← Line 6303: Should preserve Redacted
    [Value]
  >
{}

2. Schema.Redacted - Implemented as transform

File: node_modules/effect/src/Schema.ts
Lines: 6331-6352

export interface Redacted<Value extends Schema.Any>
  extends transform<Value, RedactedFromSelf<SchemaClass<Schema.Type<Value>>>>  // ← Line 6332: Uses transform
{}

export function Redacted<Value extends Schema.Any>(value: Value): Redacted<Value> {
  return transform(
    value,
    RedactedFromSelf(typeSchema(asSchema(value))),
    {
      strict: true,
      decode: (i) => redacted_.make(i),
      encode: (a) => redacted_.value(a)
    }
  )
}

3. transformOrFail - Uses input's encoded type

File: node_modules/effect/src/Schema.ts
Lines: 4117-4127

export interface transformOrFail<From extends Schema.All, To extends Schema.All, R = never> extends
  AnnotableClass<
    transformOrFail<From, To, R>,
    Schema.Type<To>,
    Schema.Encoded<From>,  // ← Line 4121: Uses input's encoded type (strips Redacted!)
    Schema.Context<From> | Schema.Context<To> | R
  >
{
  readonly from: From
  readonly to: To
}

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions