dependency-injection: Bug: Cannot use spread with the injector (Injection With Inheritance in Aurelia)
I’m submitting a bug report
- Library Version:
1.4.1
(Webpack build uses
native-modules
dist)
Please tell us about your environment:
-
Operating System: Windows 10
-
Node Version: v8.11.1
-
Yarn Version: 1.5.1
-
Webpack Version Webpack 4.16.5
-
Browser: Chrome
-
Language: TypeScript 3.0.1
Current behavior: Using the spread operator doesn’t work as per the blog post here with TypeScript, for some reason it seems to generate an additional empty object parameter?
I also have to make each property optional on the base class, which isn’t ideal but workable.
https://ilikekillnerds.com/2016/11/injection-inheritance-aurelia/
import { autoinject, containerless } from 'aurelia-framework';
import { I18N } from 'aurelia-i18n';
@autoinject
@containerless
export abstract class BaseDialog {
constructor(
protected readonly controller?: DialogController,
protected readonly element?: Element,
) {
}
}
@autoinject
export class NotesDialog extends BaseDialog {
constructor(
protected readonly i18n: I18N,
protected readonly dialogUtils: DialogUtils,
...rest
) {
super(...rest);
// rest[0] = {}; <- Why is this empty object here?
// rest[1] = DialogController
// rest[2] = Element;
console.warn('NotesDialog', rest);
}
}
Additionally, if I console.log the “NotesDialog.inject” static property at run-time, I get:
0: ƒ I18N(ea, signaler)
1: ƒ DialogUtils(dialogService, i18n)
2: ƒ Object()
Expected/desired behavior: I’d expect to be able to use the “…rest” pattern so I don’t need to update each subclass if I update the dependencies on the base class.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (19 by maintainers)
Commits related to this issue
- fix(dependency-injection): ignore ...rest TypeScript metadata Fixes #171 — committed to silbinarywolf/dependency-injection by deleted user 6 years ago
- fix(dependency-injection): ignore ...rest TypeScript metadata Fixes #171 — committed to silbinarywolf/dependency-injection by silbinarywolf 6 years ago
- fix(dependency-injection): add more tests using cases suggested by @fkleuver Fixes #171 — committed to silbinarywolf/dependency-injection by silbinarywolf 6 years ago
- fix(dependency-injection): adjust based on review Fixes #171 — committed to silbinarywolf/dependency-injection by silbinarywolf 6 years ago
Released on NPM 😃 Thanks for helping out!
I’ll attempt to get it out this evening.
Starting to look into this today
This happens to be a thing I ran into when working on DI in vNext as well. When you don’t specify the type (or invalid, like an interface) typescript simply emits the
Object
type. Frankly i’m a little surprised it does the same thing for...rest
but I suppose it makes sense to someone somewhere 😃