Skip to content

ES6 import vs @Configuration({imports: []}) #2813

Answered by Romakita
borjapazr asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @borjapazr

imports was introduced later to cover a specific usage.

In most case, ES6 import is enough. In your given example adding MyService to imports field special effect because your class is already decorated by @Injectable.

But in this example imports is required:

// Server.ts

import { Configuration } from "@tsed/di";
class MyService {
}

@Configuration({
  imports: [MyService]  // add MyService to the registry because MyService isn't decorated.
})
export class Server {}

But isn't the initial reason of the imports presences. imports field is here for the following reason:

  • to force MyService to be instanciate before the class decorated by @Module or @Configuration
  • to declare …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@borjapazr
Comment options

@Romakita
Comment options

Answer selected by borjapazr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants