-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix injection of optional properties (#1308)
* fix: update getTargets to correclty get constructorTargets when a constructor has optional arguments * chore: update ci with es6 ci test jobs * chore: add typescript config that targets es6 * style: add missing line feed * style: add missing line feed * docs: update changelog * refactor: move e6 tsconfig with the other ts config files * refactor tests for es6 es config updated for es6 ci for es6 test Co-authored-by: Dan Cavanagh <[email protected]>
- Loading branch information
1 parent
784fec7
commit d72de9b
Showing
12 changed files
with
136 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ dts | |
lib | ||
temp | ||
es | ||
es6 | ||
amd | ||
|
||
type_definitions/inversify/*.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"include": [ | ||
"./**/*.ts" | ||
], | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"target": "es6", | ||
"outDir": "../es6" | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { expect } from "chai"; | ||
import { Container, inject, injectable, optional } from "../../src/inversify"; | ||
|
||
|
||
describe("Issue 928", () => { | ||
|
||
it('should inject the right instances', () => { | ||
|
||
let injectedA: unknown; | ||
let injectedB: unknown; | ||
let injectedC: unknown; | ||
|
||
// some dependencies | ||
@injectable() class DepA { a = 1 } | ||
@injectable() class DepB { b = 1 } | ||
@injectable() class DepC { c = 1 } | ||
|
||
@injectable() abstract class AbstractCls { | ||
constructor(@inject(DepA) a: DepA, @inject(DepB) @optional() b: DepB = {b: 0}) { | ||
injectedA = a; | ||
injectedB = b; | ||
} | ||
} | ||
|
||
@injectable() class Cls extends AbstractCls { | ||
constructor(@inject(DepC) c: DepC, @inject(DepB) @optional() b: DepB = { b: 0 }, @inject(DepA) a: DepA) { | ||
super(a, b); | ||
|
||
injectedC = c; | ||
} | ||
} | ||
|
||
const container = new Container(); | ||
[DepA, DepB, DepC, Cls].forEach(i => container.bind(i).toSelf().inSingletonScope()); | ||
|
||
container.get(Cls); | ||
|
||
expect(injectedA).to.deep.eq(new DepA()); | ||
expect(injectedB).to.deep.eq(new DepB()); | ||
expect(injectedC).to.deep.eq(new DepC()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters