module@warp-drive/schema-dsl
ts
function trait(..._traits): (target) => void;Defined in: entities/compose-trait.ts:45
Class Decorator
Composes one or more Trait-decorated classes onto a Resource or Trait, populating the compiled schema's traits array with each composed trait's (dasherized) name.
Traits passed here must still be registered with the store (e.g. via store.schema.registerTrait) separately; this decorator only records which traits a resource depends on, it does not merge their fields into the compiled output.
Has no effect when stacked on an ObjectSchema-decorated class: object schemas do not compile a traits array.
Parameters
_traits
...AnyConstructor[]
Returns
(target) => void
Example
ts
import { Resource, field, trait } from '@warp-drive/schema-dsl';
import { Timestamped } from './timestamped.ts';
@Resource
@trait(Timestamped)
export class User {
@field declare name: string;
}json
{
"type": "user",
"traits": ["timestamped"]
}Since
5.9.0