From 9f4ea32c02c5dba616e2c6171c5ae09d7641a8cd Mon Sep 17 00:00:00 2001 From: Neo <80315475+Benzo-Fury@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:27:53 +1000 Subject: [PATCH] docs: add ts declaration info --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 8b020da..d7a4e11 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Awilix enables you to write **composable, testable software** using dependency i - [`container.build()`](#containerbuild) - [`container.dispose()`](#containerdispose) - [Universal Module (Browser Support)](#universal-module-browser-support) +- [Typescript Declarations](#typescript-declarations) - [Ecosystem](#ecosystem) - [Contributing](#contributing) - [What's in a name?](#whats-in-a-name) @@ -1346,6 +1347,26 @@ because they depend on Node-specific packages. - Safari >= 10 - Internet Explorer is not supported +# Typescript Declarations +If you're utilizing [TypeScript](https://www.typescriptlang.org/) and want type information on your dependencies after retrieval, or if you simply want IntelliSense support, you can craft a declaration file as follows: +```ts +// awilix.d.ts +import { AwilixContainer } from "awilix"; +import { MyServiceA } from "myServiceA.js"; +import { MyServiceB } from "myServiceB.js"; + +interface DependencyMap { + serviceA: MyServiceA; + serviceB: MyServiceA; +} + +declare module "awilix" { + function createContainer( + opts?: ContainerOptions + ): AwilixContainer; +} +``` + # Ecosystem * [`awilix-manager`](https://github.com/kibertoad/awilix-manager): Wrapper that allows eager injection, asynchronous init methods and dependency lookup by tags.