{"id":25983,"library":"ng-di-transpiler","title":"ng-di-transpiler","description":"ng-di-transpiler v0.1.10 is a dependency injection transpiler for Angular that generates platform-specific provider files at build time. It allows developers to define interfaces for tokens and create typed provider configurations, which are then transpiled into compiled provider files. The tool is designed for Angular 2+ applications and aims to reduce boilerplate and improve type safety in DI setup. It is still in early stages (v0.1.x) with experimental features like interface-based tokens. Alternatives include Angular's built-in provider factories or custom AOT compilation setups, but this package provides a dedicated transpilation step. Release cadence is sporadic with occasional bug fixes. Ships TypeScript types and uses a CLI command (ngdt) for integration.","status":"active","version":"0.1.10","language":"javascript","source_language":"en","source_url":"https://github.com/gund/ng-di-transpiler","tags":["javascript","ng","angular","angular2","di","transpiler","compiler","ioc","typescript"],"install":[{"cmd":"npm install ng-di-transpiler","lang":"bash","label":"npm"},{"cmd":"yarn add ng-di-transpiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add ng-di-transpiler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM only; library only ships TypeScript types.","wrong":"const TokenProviders = require('ng-di-transpiler')","symbol":"TokenProviders","correct":"import { TokenProviders } from 'ng-di-transpiler'"},{"note":"Used to create typed provider classes.","wrong":"","symbol":"TokenProvider","correct":"import { TokenProvider } from 'ng-di-transpiler'"},{"note":"Configuration object used in tsconfig.json, not imported directly.","wrong":"","symbol":"ngdtOptions","correct":"import { ngdtOptions } from 'ng-di-transpiler'"},{"note":"No programmatic API documented; only CLI.","wrong":"const ngdt = require('ng-di-transpiler').default","symbol":"default (CLI)","correct":"Use CLI command 'ngdt' directly as a script or npx"}],"quickstart":{"code":"// 1. Define platform tokens interface\nimport { TokenProviders, TokenProvider } from 'ng-di-transpiler';\nimport { OpaqueToken } from '@angular/core';\n\ninterface ConsoleLike {\n  log(msg: string): void;\n}\nexport const CONSOLE_TOKEN = new OpaqueToken('console');\n\nexport interface PlatformTokens extends TokenProviders {\n  console: ConsoleProvider;\n}\n\nexport class ConsoleProvider extends TokenProvider<ConsoleLike> {\n  provider: CONSOLE_TOKEN;\n}\n\n// 2. Create platform provider file: providers.browser.ts\nimport { PlatformTokens, ConsoleProvider } from './platform-tokens';\nclass BrowserLogger { log(msg: string) { console.log(msg); } }\nexport const TOKENS: PlatformTokens = {\n  console: new ConsoleProvider(BrowserLogger)\n};\n\n// 3. Run CLI to compile: ngdt --files \"src/**/providers.browser.ts\" --postfix .compiled\n// Generates providers.browser.compiled.ts","lang":"typescript","description":"Shows how to define tokens, create a provider file, and run the CLI to transpile."},"warnings":[{"fix":"Stick to using OpaqueToken/InjectionToken for token types until feature is stable.","message":"Experimental interface-as-token feature (v0.1.0) lacks tests and may be unstable.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure exported const in provider files is explicitly typed with the interface extending TokenProviders.","message":"Type checking relies on the variable type annotation; incorrect type may cause transpilation to skip or generate wrong code.","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"Use explicit --files argument or configure ngdtOptions in tsconfig.json.","message":"Only files matching the glob pattern are transpiled; mismatched patterns result in no output.","severity":"gotcha","affected_versions":">=0.0.2"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add import: import { TokenProviders } from 'ng-di-transpiler';","cause":"Missing import from ng-di-transpiler.","error":"Cannot find name 'TokenProviders'"},{"fix":"Instantiate the provider class: new SomeTokenProvider(ActualClass) instead of new SomeTokenProvider(ActualClass).","cause":"Passing class reference instead of instance to TokenProvider constructor.","error":"Type 'typeof SomeClass' is not assignable to type 'TokenProvider<T>'"},{"fix":"Install locally: npm install ng-di-transpiler --save-dev, then use npx ngdt or add script in package.json.","cause":"Package not installed or not in PATH.","error":"ngdt: command not found"},{"fix":"Ensure your platform tokens interface extends TokenProviders and the exported const is typed with that interface.","cause":"The token interface not extending TokenProviders or variable not typed correctly.","error":"No provider for TokenProviders"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}