diff --git a/README.md b/README.md index 8b020da..9c0c1b6 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"; +import { MyServiceB } from "myServiceB"; + +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.