I want to be able to set a parameter on a class which is defined in a parent with a decorator. My code looks like this:
Decorator:
const meta = (target: typeof Service, field: string) => {
if (!target.prototype.__meta__) {
target.prototype.__meta__ = {}
}
if (!target.prototype.__meta__![field]) {
target.prototype.__meta__![field] = ''
}
}
export const Suffix = (baseSuffix: string = '') => {
return (target: typeof Service) => {
meta(target, 'suffix')
target.prototype.__meta__!.suffix = baseSuffix
}
}
Service class:
export class Service {
public __meta__: any
}
Index:
@Suffix('hello world')
class TestService extends Service {}
const testService = new TestService()
console.log(testService) // prints TestService { __meta__: undefined }