Typed Inject is a robust, 100% type-safe dependency injection framework specifically designed for TypeScript applications. It allows developers to inject classes, interfaces, or primitive values, leveraging TypeScript's type system to ensure that if a project compiles, its dependencies are correctly resolved at runtime with their declared types. The current stable version is 5.0.0, released in late 2024. Major versions typically roll out with significant changes like Node.js version updates or module system migrations, as seen with the v4.0.0 (ESM migration) and v5.0.0 (Node 16 drop) releases. Its primary differentiator is its strong type-safety, which virtually eliminates runtime dependency resolution errors by shifting validation to compile time. It handles various injection patterns, including class, value, and factory providers, and supports concepts like child injectors and lifecycle control.
npm install typed-injectVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `typed-inject` by creating an injector, providing a value and a class, and then injecting a service that depends on both.
Upgrade your Node.js runtime to version 18 or later. Check `engines` field in package.json.
Migrate your project to use ES Modules with `import` statements. Ensure your `package.json` specifies `"type": "module"` or uses `.mjs` extensions for modules.
Upgrade your Node.js runtime to version 16 or later.
Ensure you are using TypeScript 3.0+ (preferably 4.5+ to avoid specific compiler bugs) and enable `--strict` or at least `--strictFunctionTypes` in your `tsconfig.json`.
Add `"strictFunctionTypes": true` or `"strict": true` to your `compilerOptions` in `tsconfig.json`.
Change `const { createInjector } = require('typed-inject');` to `import { createInjector } from 'typed-inject';` and ensure your project is configured for ESM.Verify that `appInjector.provideValue`, `provideClass`, or `provideFactory` methods are called for all required dependencies (e.g., `appInjector.provideValue('someDependency', instance);`) and that the token names match exactly.Ensure the class has a `public static inject = ['dependencyName1', 'dependencyName2'] as const;` property, and that the names listed correspond to correctly provided dependencies and match the constructor's parameters in order and type.
No dependency data recorded yet.