Hyperlinkv0.8.0-beta.28

Schema

Schema.tagDefaultOmitfunctioneffect/Schema.ts:6010
<Tag extends SchemaAST.LiteralValue>(
  literal: Tag
): withDecodingDefaultKey<tag<Tag>, never>

Creates a literal _tag schema that is omitted from encoded output.

When to use

Use to decode data that omits the discriminator field while still constructing values with a _tag for tagged union matching.

Details

The tag is filled during decoding and construction, like tag, but is omitted when encoding.

Example (Omitting tags during encoding)

import { Schema } from "effect"

const A = Schema.Struct({
  _tag: Schema.tagDefaultOmit("A"),
  value: Schema.Number
})

// Encode strips the _tag field
const encoded = Schema.encodeUnknownSync(A)({ _tag: "A", value: 1 })
// encoded: { value: 1 }
constructorstag
Source effect/Schema.ts:60103 lines
export function tagDefaultOmit<Tag extends SchemaAST.LiteralValue>(literal: Tag) {
  return tag(literal).pipe(withDecodingDefaultKey(Effect.succeed(literal), { encodingStrategy: "omit" }))
}