Argument of type 'Isms91Options' is not assignable to parameter of type 'string | URL'

Viewed 359

I am new in typescript and just trying to convert Msg91 NodeJS API code to typescript but got an error while compiling the code. i.e 'Argument of type 'Isms91Options' is not assignable to the parameter of type "string | URL'."

I tried to remove all the possible type of error but I think I missed some.

interface IoptionsType {
    phoneNumber: string;
    message: string;
}

interface IheadersType {
  authkey: string;
  contentType: string;
}

interface Isms91Options {
    method: string;
    hostname: string;
    port: string;
    path: string;
    headers: IheadersType;
}

export const sendSms = (data: IoptionsType) => {
  const {message, phoneNumber} = data;
  const option: Isms91Options = {
                  headers: {
                    authkey: "XXXXXXXXXXXXX",
                    contentType: "application/json"
                  },
                  hostname: "api.msg91.com",
                  method: "POST",
                  path: `http://api.msg91.com/api/v2/sendsms?message=${message}&authkey=XXXXXXXXXXXXXXX&`
                        + `mobiles=+91${phoneNumber}&route=4&sender=XXXXX&country=91&unicode=1`,
                  port: null,
  };

  const req = http.request(option, (res: Response) => {
    const chunks: any[] = [];
    res.on("data", (chunk) => {
      chunks.push(chunk);
    });

    res.on("end", () => {
      log.info(Buffer.concat(chunks));
    });
  });

  req.write(JSON.stringify({
    country: "91",
    route: "4",
    sender: "XXXXXX",
    sms:
     [ { message: "testing", to: [ "XXXXXXX" ] } ] }));
  req.end();
};

This is the error I am facing while compiling the code error TS2345: Argument of type 'Isms91Options' is not assignable to parameter of type 'string | URL'. Type 'Isms91Options' is missing the following properties from type 'URL': hash, host, href, origin, and 7 more.

0 Answers
Related