question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Cannot use spread with the injector (Injection With Inheritance in Aurelia)

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
EisenbergEffectcommented, Dec 18, 2018

Released on NPM 😃 Thanks for helping out!

1reaction
EisenbergEffectcommented, Dec 18, 2018

I’ll attempt to get it out this evening.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Injection With Inheritance in Aurelia - I Like Kill Nerds
Let's use the spread operator and rest parameters to get our parent dependencies: import {inject} from 'aurelia-framework'; import {Router} ...
Read more >
Cannot autoinject abstract classes in aurelia-dependency ...
This breaks an inheritance-based scenario common in our application: we use abstract, generic classes for viewModels with high-level shared ...
Read more >
Aurelia: partial injection for base class - Stack Overflow
Luckily, Aurelia DI supports inheritance when defining injects (be ... to be specified explicitly and can be passed using spread operator.
Read more >
Handling Dependency Injection in Inherited Classes
The solution to this problem is really quite simple. Rather than injecting the dependencies directly, create a new class that contains the ...
Read more >
U5L1-Spell-Checker.xml - The Beauty and Joy of Computing
... ,could,after,even,because,us,said,good,way,two,should,work,use,through,see ... ,army,professionals,obama,holding,slow,responsibility,spread,square,sweet ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found