Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configService.get<T> returns string #361

Open
1 of 4 tasks
jpramondon opened this issue Feb 8, 2021 · 1 comment
Open
1 of 4 tasks

configService.get<T> returns string #361

jpramondon opened this issue Feb 8, 2021 · 1 comment

Comments

@jpramondon
Copy link

Issue type:

  • question
  • bug report
  • feature request
  • documentation issue

nestjs-config version
0.6.3

@nestjs/common+core or other package versions

  • @nestjs/common: 7.6.11
  • @nestjs/core: 7.6.11

Excepted behavior

Given the following .env.local file,

KEY1=3000
KEY2=false

When performing this:

const confValue = this.configService.get<number>("KEY1", 5000);

then confValue's type should be a number. At least that's what the get method's signature suggests and that's great.

Actual behavior or outcome (for issue)

However, when doing:

const confValue = this.configService.get<number>("KEY1", 5000);

... then confValue is actually a string, which is confirmed by typeof confValue

... which gets worse when dealing with booleans:

const confValue = this.configService.get<boolean>("KEY2", false);
if (confValue) {
  // truthy expression which always returns true:  if "false" => true
}

Thanks for your help !

Replication/Example

@Module({
  imports: [
    ConfigModule.forRoot({ envFilePath: ['.env.local'], cache: true })
  ],
  controllers: [ ],
  providers: [MyManager],
})
export class AppModule { }
@Injectable()
export class MyManager {

    @Inject()
    private configService: ConfigService;

    public async doStuff(): Promise<void> {
        const confValue1 = this.configService.get<number>("KEY1", 5000);
        const confValue2 = this.configService.get<boolean>("KEY2", false);
    }
}
@micalevisk
Copy link

nestjs-config version
0.6.3

but nestjs-config never had this version. Maybe you're talking about @nestjs/config?

$ npm info nestjs-config versions
[
  '1.0.0',        '1.0.1',        '1.1.0',
  '1.2.0',        '1.2.1',        '1.2.2',
  '1.2.3',        '1.2.4',        '1.2.5',
  '1.2.6',        '1.2.7',        '1.2.8',
  '1.2.9-alpha',  '1.2.9',        '1.3.0',
  '1.3.2',        '1.3.21',       '1.4.0',
  '1.4.1',        '1.4.2',        '1.4.3',
  '1.4.4',        '1.4.5',        '1.4.6',
  '1.4.7',        '1.4.8',        '2.0.0-beta',
  '2.0.0-beta.1', '2.0.0-beta.2', '2.0.0-beta.3'
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants