-
Notifications
You must be signed in to change notification settings - Fork 718
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
Use default class property for @optional injected properties #1467
Conversation
a131d35
to
361c7a3
Compare
Currently the @optional tag overrides class properties defined with typescript-style default values: ```typescript @Injectable() class Ninja { @Inject(Weapon) @optional() weapon: Weapon = new Katana(); .... } ``` this currently sets the weapon property to `undefined` if no Weapon is present in the container. My proposed change allows does not override the default and results in the weapon property being set to new Katana(). (Default values in the constructor already work, but I would prefer not to add boilerplate constructors if this solution is possible.)
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## master #1467 +/- ##
==========================================
+ Coverage 99.56% 99.61% +0.05%
==========================================
Files 53 53
Lines 1364 1568 +204
Branches 196 206 +10
==========================================
+ Hits 1358 1562 +204
Partials 6 6
... and 22 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
LGTM. |
Any updates on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
@haaijman-imagem can you update the branch? After that I would say we can merge it |
Description
Currently the @optional tag overrides class properties defined with typescript-style default values:
this currently sets the weapon property to
undefined
if no Weapon is present in the container. My proposed change allows does not override the default and results in the weapon property being set to new Katana().(Default values in the constructor already work, but I would prefer not to add boilerplate constructors if this solution is possible.)
Related Issue
@optional property injection overrides default
Motivation and Context
How Has This Been Tested?
By copying the test case for optional constructor injection but moving the injection to property injection and then running npm test
Types of changes
Checklist: