Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
Typescript utility function to make Axios requests

I'm trying to make a utility function for Axios requests.

I started by making an alias of AxiosConfig at global.d.ts:

import { Method } from 'axios';
export {};

declare global { 
    type AxiosConfig = {url: string, method: Method, data: object};
}

Then, at my utils.ts I created the following function:

import axios, { AxiosResponse } from 'axios';
import * as https from 'https';

export async function axiosReq(options: AxiosConfig): Promise<AxiosResponse<unknown, any>> {
  try {
    const data = await axios({
        url: options.url,
        method: options.method,
        data: options.data,
        httpsAgent: new https.Agent({
          rejectUnauthorized: false
        })
    });
    return data;
  } catch (error) {
    console.log(error)
    throw new Error('Failed to fetch videos...')
  }
}

Finally, using the function:

import { axiosReq } from "../utils";

const AxiosConfig = { 
    url: 'https://172.24.14.12/api/baseline', 
    method: 'POST',
    data: {}
    };
const res = await axiosReq(AxiosConfig);

The node crashes at the start (even before using axiosReq). Only when I comment out const res = await axiosReq(AxiosConfig) node starts without crashing. I don't receive any informative errors.

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're treating AxiosConfig as a value or variable when it's really just a type. Try

const postBaseline: AxiosConfig = {...

then replace AxiosConfig in the res call with postBaseline

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda