Injecting providers #1420
-
Assuming I have an image service provider registered in AppProvider as follows: this.$container.singleton("Adonis/Addons/ImageService", () => {
const config = this.$container.use("Adonis/Core/Config").get("image");
return new ImageService(config);
}); If I try injecting it in my controller as: import imageServiceProvider from "@ioc:Adonis/Addons/ImageService"; typescript always yells at me because it can't resolve @IOC:Adonis/Addons/ImageService. I do get around the warning by doing this: //@ts-ignore
import imageServiceProvider from "@ioc:Adonis/Addons/ImageService"; And my question, is there a neater and better way of injecting my dependencies from the ioc container without adding //@ts-ignore? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Coz typescript has no idea that a module named Also check the source code of AdonisJS packages to see how ambient modules are defined |
Beta Was this translation helpful? Give feedback.
Coz typescript has no idea that a module named
@ioc:Adonis/Addons/ImageService
exists. You have to define it using an ambient module.Also check the source code of AdonisJS packages to see how ambient modules are defined