inversify / InversifyJS

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

Error message unclear #1386

Closed penguinsAreFunny closed 1 week ago

penguinsAreFunny commented 3 years ago

I got the error "Metadata key was used more than once in a parameter: inject".

You can find the error constant: https://github.com/inversify/InversifyJS/blob/master/src/constants/error_msgs.ts You can find it used: https://github.com/inversify/InversifyJS/blob/master/src/annotation/decorator_utils.ts

I do not understand what this error message means. Can someone explain this error message to me? What is a metadata key?

At this point I am not sure, if the error message is not ideal, if this bug should not occure (at least in my code) at all or if I am only not understanding the error message.

I would really appreciate it, if you could help me understand this error.

My assumptions: If the same class name and static property name occurres twice in one application it will lead to an error.

export class Class1 { @inject(TYPES.property) static property }

somewhere else, f.e. in a node_modules package export class Class1 { @inject(TYPES.property) static property }

Is this correct? Are the Meta-key the class-names + property-names? Therefore probably not unique? If InversifyJS was implemented that way I think this is a mistake as Typescript does support such use cases. If my assumptions are true I think that the keys should not be the class-names + property-names but should be generated.

notaphplover commented 1 week ago

The error message means you tried to apply twice an @inject decorator to the same construcot parameter or property.