How to use with other decorators?
See original GitHub issuefunction logNew() {
return <T extends constructor<any>>(constructor: T) => {
return class extends constructor {
constructor(...args: any[]) {
super(...args);
console.log("CREATED", args)
}
}
};
}
class Foo {
value = "foo"
}
@logNew()
@injectable()
class Bar {
constructor(foo: Foo){
console.log(foo.value)
}
}
const bar = container.resolve(Bar)
foo is undefined
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Primer on Python Decorators
The other way to use decorators on classes is to decorate the whole class. This is, for example, done in the new dataclasses...
Read more >Chain Multiple Decorators in Python - GeeksforGeeks
Example 1: For num() function we are applying 2 decorator functions. Firstly the inner decorator will work and then the outer decorator.
Read more >Python Decorators (With Examples) - Programiz
In Python, a decorator is a design pattern that allows you to modify the functionality of a function by wrapping it in another...
Read more >Python Decorators: From Simple Decorators to Nesting Multiple
The way to use parameters with decorator is by sending them after using @ symbol with the name of the decorator method. In...
Read more >Python: how to use multiple decorators on one function
Decorators are a confusing Python topic, especially when you see two or more used at once! Here's a simple explanation of what's going...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I actually ran into this same issue and found out that I could just pass on the reflection metadata onto the new constructor. Now the new constructor gets called with the injected dependencies. Not sure if this is the correct approach, but it seems to work for now. See below:
Caveat is that I have to register
MyDecoratorbelow the tsyringe one, so that tsyringe registers my overriden constructor reference. For example:And then I’m doing
@skiptirengu, @user753 Had the same issue but only when I was using @babel/typescript presets. When I changed it to ts-loader issue dissapeared.
It’s probably because resolving of decorators is other in both cases.
Code from
injectabledecorator passed with paraminjectdecorator is no more giiving errors and getting resolved.After some tries I’ve managed that generating keys for
injectionTokensis working. It’s for sure related tobabel-plugin-transform-typescript-metadataand@babel/typescript.