You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have 2 simple classes and an index.ts entry script.
index.ts looks like this:
import ConfigHelper from './config/ConfigHelper'
const configHelper: ConfigHelper = new ConfigHelper()
configHelper.testOutput()
console.log(configHelper.fsAsyncFactory)
ConfigHelper looks like this:
import {AutoWired, Inject} from 'typescript-ioc'
import FsAsyncFactory from '../fs/FsAsyncFactory'
export class ConfigHelper {
@Inject
public fsAsyncFactory: FsAsyncFactory
public testOutput(): void {
console.log('### ConfigHelper.testOutput')
}
}
export default ConfigHelper
FsAsyncFactory looks like this:
import * as BB from 'bluebird'
import * as fs from 'fs'
export class FsAsyncFactory {
private fsAsync: any = null
public getFsAsync(): any {
if (this.fsAsync === null) {
this.fsAsync = BB.promisifyAll(fs)
}
return this.fsAsync
}
}
export default FsAsyncFactory
But when I run it I get an output of:
### ConfigHelper.testOutput
.../internalprojects/node-di-mocha-test/node_modules/typescript-ioc/es5.js:137
throw new TypeError('Invalid type requested to IoC ' +
^
TypeError: Invalid type requested to IoC container. Type is not defined.
at checkType (.../internalprojects/node-di-mocha-test/node_modules/typescript-ioc/es5.js:137:15)
at Function.IoCContainer.bind (.../internalprojects/node-di-mocha-test/node_modules/typescript-ioc/es5.js:98:9)
at Function.IoCContainer.get (.../internalprojects/node-di-mocha-test/node_modules/typescript-ioc/es5.js:108:35)
at ConfigHelper.get [as fsAsyncFactory] (.../internalprojects/node-di-mocha-test/node_modules/typescript-ioc/es5
.js:119:85)
at Object.<anonymous> (.../internalprojects/node-di-mocha-test/dist/index.js:5:25)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
I tried your code, but it worked as expected here. No error occurred. I saw that the version declared in package.json was 1.0.2. When I ran npm i, it installed the newest 1.1.1.
I don't know what caused the error to you, but can you try again with this new version?
I met same error message when missing emitDecoratorMetadata: true in my tsconfig.json ("version": "1.2.5")
[2019-10-07T23:52:26.965] [FATAL] launcher - Invalid type requested to IoC container. Type is not defined. TypeError: Invalid type requested to IoC container. Type is not defined.
at checkType (service/node_modules/typescript-ioc/src/typescript-ioc.ts:356:15)
at Function.bind (service/node_modules/typescript-ioc/src/typescript-ioc.ts:301:9)
at Function.get (service/node_modules/typescript-ioc/src/typescript-ioc.ts:312:49)
at RuntimeImpl.get [as hostingService] (service/node_modules/typescript-ioc/src/typescript-ioc.ts:334:85)
I think(proposal) this case should be detected in runtime with a warning message. @adamdry if you you agree with my proposal let me know and I will return with a merge request...
I have 2 simple classes and an index.ts entry script.
index.ts looks like this:
ConfigHelper looks like this:
FsAsyncFactory looks like this:
But when I run it I get an output of:
I have a public repo here if you'd like to try for yourself (use this specific commit): adamdry/node-di-mocha-test@1204758
To run the demo:
npm i
npm run dev
I imagine I'm doing something stupid though... :)
Thanks.
The text was updated successfully, but these errors were encountered: