Constexport class Person extends Type.makeObject<Person>(DXN.make('com.example.type.myType', '0.1.0'))(Schema.Struct({
name: Schema.String,
})) {}
export class Tag extends Type.makeObject<Tag>(DXN.make('com.example.type.tag', '0.1.0'))(
{ label: Schema.String },
Annotation.LabelAnnotation.set(['label']),
) {}
Factory function to create an ECHO object type.
Returns a
Type.Typeentity — a live, in-memoryTypeSchemainstance, NOT aSchema.Schema. UseType.InstanceType<typeof Foo>for the instance type andType.getSchema(Foo)to obtain the underlying Effect Schema.The entity's id defaults to
EntityId.deterministic(typename, version)so constructing a type never reachescrypto.getRandomValues()— required for Cloudflare workerd, which forbids RNG calls in global (module-evaluation) scope. Pass{ id }to override (e.g. withEntityId.random()from a request handler).Giving the type a nominal class name keeps its inferred type portable for declaration emit: structural expansion (which can pull in unnameable union members from referenced schemas) is replaced by a reference to the class.
The second call takes either a schema, or struct fields (wrapped in
Schema.Struct) with an optional function that pipes annotations onto the struct.