2

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();
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • You have to provide more sample code to show whats going on here. Nobody knows what is happening inside your ConfigService. – Ele Nov 24 '21 at 10:26
  • The code you provided should work. I am using the same thing it's working fine for me. Maybe check your validation and configuration files. – Rasool Khan Nov 24 '21 at 11:29
  • Like i mentioned before it worked in my old project but when i created new and the version of config 1.1.2 not working. What version of your config? – Ridwan Sidik Nov 24 '21 at 11:36
  • i just try install again the nestjs/config and it already changed to 1.1.3 and now worked. the problem was in version 1.1.2 – Ridwan Sidik Nov 24 '21 at 11:43
  • You can add an answer if you resolved it instead of editing solved in the title – Suraj Rao Nov 24 '21 at 12:21
  • I have the same problem and I'm using version 2.2.0! – Mark Robson Jan 12 '23 at 12:11

1 Answers1

1

Fixed on @nestjs/config version 1.1.3

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 24 '21 at 15:57