Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'reflect-metadata'
- import {Container, Inject, Service} from "typedi";
- @Service()
- export class Bla {}
- const testconfig = {}
- type ConfigType = typeof testconfig
- @Service()
- export class Base {
- public constructor(
- @Inject('config')
- protected cfg: ConfigType, //This is not injected
- protected bla: Bla // if this is coming from a module w/ import 'reflect-metadata'
- ) {
- if(!cfg){
- throw Error('expected typedi to inject cfg')
- }
- console.log('cfg injected')
- }
- }
- @Service()
- export class Child extends Base {}
- if (require.main === module) {
- Container.set('config', testconfig)
- Container.get(Base) //works
- Container.get(Child) //inherited constructor does not receive a named dependency
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement