declare const Reflect ; param { ng . IModule } ngModule param { string } injectable returns { string } function createOptionalInject ( ngModule , injectable ) { const name = `@Optional(${ injectable })` ; const factory = $injector => { if ( $injector . has ( injectable ) ) { return $injector . get ( injectable ) ; } return null ; } ; factory . $inject = [ '$injector' ] ; ngModule . factory ( name , factory ) ; return name ; } export function inject ( ngModule , target ) { const annotations = target . __annotations__ || { } ; const injectables = [ ] ; if ( annotations . inject ) { annotations . inject . forEach ( ( injectable , index ) => { let name = typeof injectable === 'string' ? injectable : injectable . name ; if ( annotations . optional && annotations . optional [ index ] === true ) { name = createOptionalInject ( ngModule , name ) ; } injectables [ index ] = name ; } ) ; } if ( Reflect . hasMetadata ( 'design:paramtypes' , target ) ) { Reflect . getMetadata ( 'design:paramtypes' , target ) . forEach ( ( type , index ) => { if ( type . name !== 'Object' && injectables [ index ] === undefined ) { let name = type . name ; if ( annotations . optional && annotations . optional [ index ] === true ) { name = createOptionalInject ( ngModule , name ) ; } injectables [ index ] = name ; } } ) ; } target . $inject = injectables ; }