Hyperlinkv0.8.0-beta.28

Schema

Schema.asClassfunctioneffect/Schema.ts:2248
<S extends Top>(schema: S): S & { new (_: never): {} }

Transforms a schema into a class that can be extended with extends. The resulting class inherits the full schema API (e.g. annotate) and can define static methods that reference this.

Example (Wrapping a primitive schema)

import { Schema } from "effect"

class MyString extends Schema.asClass(Schema.String) {
  static readonly decodeUnknownSync = Schema.decodeUnknownSync(this)
}

console.log(MyString.decodeUnknownSync("a"))
// "a"
constructors
Source effect/Schema.ts:22485 lines
export function asClass<S extends Top>(schema: S): S & { new(_: never): {} } {
  // oxlint-disable-next-line @typescript-eslint/no-extraneous-class
  class Class {}
  return Object.setPrototypeOf(Class, schema)
}