-
Notifications
You must be signed in to change notification settings - Fork 716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
whenTargetIsDefault not working in combination with optional #1190
Comments
Hi @rainerschuster I'll have a look. Thank you for your report |
Hi @rainerschuster it makes sense to me to update the actual behavior to cover your expectations. What do you think @PodaruDragos , @dcavanagh? |
hi @notaphplover isn't the behavior correct ? #411 (comment) |
Hi @PodaruDragos , I am not sure, I've been reading the docs:
So I think if the binding is declared, the If we look the current implementation of public whenTargetIsDefault(): interfaces.BindingOnSyntax<T> {
this._binding.constraint = (request: interfaces.Request) => {
const targetIsDefault = (request.target !== null) &&
(!request.target.isNamed()) &&
(!request.target.isTagged());
return targetIsDefault;
};
return new BindingOnSyntax<T>(this._binding);
} It seems to be all right but, looking at public isTagged(): boolean {
return this.metadata.some((m) =>
(m.key !== METADATA_KEY.INJECT_TAG) &&
(m.key !== METADATA_KEY.MULTI_INJECT_TAG) &&
(m.key !== METADATA_KEY.NAME_TAG) &&
(m.key !== METADATA_KEY.UNMANAGED_TAG) &&
(m.key !== METADATA_KEY.NAMED_TAG));
} It's kind of weird, if the target has the public isTagged(): boolean {
return this.metadata.some((m) =>
(m.key !== METADATA_KEY.INJECT_TAG) &&
(m.key !== METADATA_KEY.MULTI_INJECT_TAG) &&
(m.key !== METADATA_KEY.NAME_TAG) &&
(m.key !== METADATA_KEY.UNMANAGED_TAG) &&
(m.key !== METADATA_KEY.NAMED_TAG) &&
(m.key !== METADATA_KEY.OPTIONAL_TAG));
} which would solve the issue, the |
Hi @rainerschuster the issue is fixed in the master branch now! :) |
Thanks for fixing! |
You are very welcome 😃 we expect to release a new version soon, I'm closing the issue. Feel free to ping me if anything is wrong and I'll reopen it immediately. |
If a property is declared as @optional and the types are bound with whenTargetIsDefault the property is undefined.
Expected Behavior
The following example should inject Katana for the optional katana field.
Current Behavior
katana is undefined. If the decorator optional is removed it works as expected.
Possible Solution
use container.get(TYPES.Weapon);
Steps to Reproduce (for bugs)
Your Environment
The text was updated successfully, but these errors were encountered: