Ridwan Sidik
Ridwan Sidik

Reputation: 41

Getting error while using env variables as ConfigService in NestJs

i'm using nestjs for project i have no issue using "@nestjs/config" before version 1.1.2 but when i created new one while copy paste from my old source code into my new one especially in main.ts it gives me error Argument of type 'string' is not assignable to parameter of type 'never'. when i passed string LISTENING_PORT into get function of configService but it worked in my old project what's the problem and how to solve this problem? thanks in advance. here's my sample code

import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as helmet from 'helmet';
import { CustomExceptionFilter } from './exceptions/custom-exception.filter';
import { CustomValidationPipe } from './pipes/custom-validation.pipe';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.enableCors();
  app.use(helmet());
  app.useGlobalPipes(new CustomValidationPipe());
  const configService = app.get(ConfigService);
  app.useGlobalFilters(new CustomExceptionFilter(configService));
  const listeningPort = configService.get('LISTENING_PORT');
  const config = new DocumentBuilder()
    .setTitle('API Documentation')
    .setDescription('API description')
    .setVersion('0.1')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, document);
  await app.listen(listeningPort);
}
bootstrap();

Upvotes: 2

Views: 1398

Answers (1)

Ridwan Sidik
Ridwan Sidik

Reputation: 41

Fixed on @nestjs/config version 1.1.3

Upvotes: 1

Related Questions