inversify / InversifyJS

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
http://inversify.io/
MIT License
11.02k stars 712 forks source link

Decorator[@targetName] error TS1239: Unable to resolve signature of parameter decorator when called as an expression #1556

Open wangsyiiz opened 5 months ago

wangsyiiz commented 5 months ago

Expected Behavior

There should not be any error occurred when @targetName be used at constructor

Current Behavior

constructor(@inject("IService") @targetName("queueService") ticketQueue: IService) { }

error TS1239: Unable to resolve signature of parameter decorator when called as an expression

Possible Solution

Steps to Reproduce (for bugs)

Context

Your Environment

Stack trace

wangsyiiz commented 5 months ago

ok, actually I found another decorator @named can be used in normally, but still in documentation it indicates to use @targetName, is that a wrong description?

gustavohenke commented 4 months ago

Both are documented, here's @named's: https://github.com/inversify/InversifyJS/blob/7619dd4395516fa53f435d08f30cead349901be8/wiki/named_bindings.md

The error comes from the signature of @targetName not properly matching the decorator signature anymore. It's new on Typescript 5: https://github.com/microsoft/TypeScript/issues/52435


That said, I don't understand the difference between @named and @targetName. @named seems slightly better supported, and @targetName's docs mention the use of namedConstraint, which doesn't work because it works on a different tag.

gustavohenke commented 4 months ago

Created #1561 to fix this.