I try to write a dynamic module. Check the gist from 馃檹 @evolkmann. I get a compiler error:
Returned expression type ... is not assigneable to DynamicModule
If you switch to useClass
it seamlessly works. What am I doing wrong or is it a bug?
https://gist.github.com/evolkmann/1019721d46304df3d8ff7adbca87d8ec
No compiler error since this should work acc. to official docs and I assume gist worked once.
It works with
{
provide: MyLibService,
useFactory: () => {
return new MyLibService(type);
},
}
But it should accept a value too...?
"@nestjs/common": "^6.7.2",
"@nestjs/core": "^6.7.2",
For Tooling issues:
- Node version:
"node": "10.16.2"
"npm": "6.10.3"
- Platform: Mac
Others:
Please, provide a minimal repository which reproduces your issue.
@mambax maybe you can find more clarification from the blog post referencing the gist you mentioned. I don't know if you read it before coming to the gist.
As @kamilmysliwiec mentioned, it is hard to find your specific problem without an explicit example.
Maybe provide some code and I can try to help.
@mambax you might find this blog post helpful.
Hey all
I learned from your posts, I read them before, here is the repo:
https://github.com/mambax/use-value-bug
I am still not excluding a layer 8 problem (me) I just don't get what could be wrong :(
This works btw:
Hi @mambax, for me your code works fine. The only thing which has to be changed is the app module. You have to call the register()
method there.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
@Module({
imports: [
AuthModule.register({
type: 'jwt'
})
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
@evolkmann Thanks for checking. I wonder what is wrong with my IDE then. The register call from you of course is missing, but will it solve the typing error above?
@mambax I don't know, for me there are no errors, with and without the register()
-call. I installed the exact dependencies defined in the package-lock.json
. I am using VS Code, but IntelliJ should also handle it of course.
@evolkmann thanks for helping out anyway, I don't get what is wrong with that thing 馃槩
馃幒
Turns out, rm -rf .idea
does not completely invalidate all caches, weird! I also deleted caches File > Invalidate caches / Restart
and now it works. Sorry everyone to bother.
this change for me in the new version 6.7.2.
GraphQLModule.forRootAsync({
imports: [LoggerModule],
inject: [LoggerService],
useFactory: (logger: LoggerService) => {
return new GqlConfigService(logger).createGqlOptions();
}
}),
to
GraphQLModule.forRootAsync({
imports: [LoggerModule],
inject: [LoggerService],
useFactory: (logger: LoggerService) => {
return new GqlConfigService(logger[0]).createGqlOptions();
}
}),
GqlConfigService(logger)
-> GqlConfigService(logger[0])
somehow the parameter is injected as an array ?
Can confirm useFactory has stopped working for us where inject is an array.
@angelov-todor @dboskovic just fixed in @nestjs/[email protected]
. Thanks for reporting!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.