Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add ts declaration info #346

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why .js?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why .js?

Oops. Sorry


interface DependencyMap {
serviceA: MyServiceA;
serviceB: MyServiceA;
}

declare module "awilix" {
function createContainer<T extends DependencyMap = DependencyMap>(
opts?: ContainerOptions<T>
): AwilixContainer<T>;
}
```

# Ecosystem

* [`awilix-manager`](https://github.com/kibertoad/awilix-manager): Wrapper that allows eager injection, asynchronous init methods and dependency lookup by tags.
Expand Down