effect
effect copied to clipboard
Schema: Create API to add annotations to Class schemas
What is the problem this feature would solve?
As far as I can tell there is no straightforward way to annotations to Class schemas.
What is the feature you are proposing to solve the problem?
https://discord.com/channels/795981131316985866/1194587684501454898/1195010272587423744
gcanti: I think classes should have their API to add annotations gcanti: or maybe just an annotation parameter after fields (or both)
What alternatives have you considered?
class MyModel extends S.Class<MyModel>()({}) {}
const _MyModel = pipe(
MyModel,
S.description('Some description`),
)
export { _MyModel as MyModel }
// from Patrick Roza: https://discord.com/channels/795981131316985866/1194587684501454898/1195008183798870018
export function annotate(annotations: S.DocAnnotations) {
return (cls: any) => {
const newCls = class extends cls {
static get ast() {
return AST.mergeAnnotations(
cls.ast,
toAnnotations(annotations)
)
}
} as any
Object.defineProperty(newCls, "name", { value: cls.name })
return newCls
}
}