Using static properties for schema transformations and decoding in TypeScript

class DocEntry extends Schema.Class < DocEntry > ("DocEntry")({
    _tag: Schema.String,
    module: Schema.Struct({
        name: Schema.String,
    }),
    project: Schema.String,
    name: Schema.String,
    description: Schema.optionalWith(Schema.String, {
        as: "Option",
        nullable: true,
    }),
    deprecated: Schema.Boolean,
    examples: Schema.Array(Schema.String),
    since: Schema.String,
    category: Schema.optionalWith(Schema.String, {
        as: "Option",
        nullable: true,
    }),
    signature: Schema.optionalWith(Schema.String, {
        as: "Option",
        nullable: true,
    }),
    sourceUrl: Schema.String,
}) {
    static readonly Array = Schema.Array(this)
    static readonly decode = Schema.decodeUnknown(this)
    static readonly decodeArray = Schema.decodeUnknown(this.Array)
}


Hello, I am reading researching the discord bot repo and I found the code above in: https://github.com/Effect-TS/discord-bot/blob/main/src/DocsLookup.ts

I really like the implementation of static readonly Array = Schema.Array(this) and I was wondering would it be possible to reuse this logic but for, for example, ommiting or extending this model. Could this be a way of implementing different view modes for same entity?

And secondly what is the logic behind decode & decodeArray, what is the use case for that?
Was this page helpful?