Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Type 'string[]' is not assignable to type 'string' in nestjs

I am trying to download file by calling external API in nestjs.
Below is my code in service

import { Injectable } from '@nestjs/common';
import * as fs from "fs";
import * as axios from "axios";
@Injectable()
export class FileService {
  saveFile() {
    return axios.default
      .get("https://www.nseindia.com/")
      .then((res) => {
        return axios.default.get(
          "https://www.nseindia.com/api/option-chain-indices?symbol=BANKNIFTY",
          {
            headers: {
              cookie: res.headers["set-cookie"],
            },
          }
        );
      })
      .then((res) => {
        //console.log(res.data);
        let data = JSON.stringify(res.data);
        fs.writeFileSync("../files/option-chain-indices.json", data);
        return data;
      })
      .catch((err) => {
        console.log(err);
      });
  }
}

I am getting error as below

error TS2322: Type 'string[]' is not assignable to type 'string'.

cookie: res.headers['set-cookie']

how can I solve this problem?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Can you change below line of code as follows?

cookie: res.headers["set-cookie"] --> cookie: res.headers["set-cookie"].join(';')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading