TypeDI
Github
Current Release
Current Release
  • Old documentation
  • Getting Started
  • Usage Guide
    • Container API
    • @Service decorator
    • @Inject decorator
    • Service Tokens
    • Inheritance
    • Usage with TypeORM
  • Advanced Usage
    • Creating custom decorators
    • Using scoped container
    • Transient services
  • Usage without TypeScript
    • Getting Started
    • Usage
      • Old documentation
Powered by GitBook
On this page
  • Installation
  • Basic usage
  • Limitations

Was this helpful?

  1. Usage without TypeScript

Getting Started

PreviousTransient servicesNextUsage

Last updated 3 years ago

Was this helpful?

It's possible to use TypeDI without TypesScript, however some of the functionality is limited or not available. These differences are listed below in the section.

Installation

To start using TypeDI with JavaScript install it via NPM:

npm install typedi

Basic usage

The most basic usage is to request an instance of a class definition. TypeDI will check if an instance of the class has been created before and return the cached version or it will create a new instance, cache and return it.

import { Container } from 'typedi';

class ExampleClass {
  print() {
    console.log('I am alive!');
  }
}

/** Request an instance of ExampleClass from TypeDI. */
const classInstance = Container.get(ExampleClass);

/** We received an instance of ExampleClass and ready to work with it. */
classInstance.print();

Limitations

To be written...

For more advanced usage examples and patterns please read the .

next page
Limitations