Error Argument is not assignable to parameter of type 'AxiosRequestConfig'

grubbyGerbil

I want to be able to delete items of a list fetched from MongoDB.

Items of an array of the list are retrieved from MongoDB and displayed in React app (I use Typescript).

Unfortunately, I get error HERE I get error Argument of type '{ itemId: any; }' is not assignable to parameter of type 'AxiosRequestConfig'

ExpensesListItem.tsx

import React from "react";
import { IconButton, ListItem, ListItemSecondaryAction, ListItemText } from "@material-ui/core";
import DeleteIcon from '@material-ui/icons/Delete';
import { ExpenseAndAmountObject } from '../ExpenseAndAmountObject';
import axios from 'axios';
interface Props {
    expenseTitle: string;
    expenseAmount: string;
    currencySymbol: string;
    item: ExpenseAndAmountObject;
    expenseAndAmountList: Array<ExpenseAndAmountObject>;
    setExpenseAndAmountList: (value: Array<ExpenseAndAmountObject>) => void;
  }

const ExpensesListItem: React.FC<Props> = (
    {
        expenseTitle,
        expenseAmount,
        currencySymbol,
        item,
        expenseAndAmountList,
        setExpenseAndAmountList
    }: Props) => {

        const DeleteListItem = (toBeDeletedItemId: any) => {
        setExpenseAndAmountList(expenseAndAmountList.filter(el => el._id !== toBeDeletedItemId));

        axios.delete('http://localhost:4000/app/expenseslist',{itemId:toBeDeletedItemId}) 
//HERE I GET THE ERROR Argument of type '{ itemId: any; }' is not assignable to parameter of type 'AxiosRequestConfig'
        .catch(function (error) {
            console.log(error);
        });
    }
    return (
        <>
            <ListItem className="list-item">
                <ListItemText primary={expenseTitle} secondary={expenseAmount + currencySymbol} />
                <ListItemSecondaryAction>
                    <IconButton onClick={()=>DeleteListItem(item._id)} edge="end">
                        <DeleteIcon className="delete-btn" />
                    </IconButton>
                </ListItemSecondaryAction>
            </ListItem>
        </>
      );
  }
  
export default ExpensesListItem;

routes.js

 router.delete('/expenseslist', (request, response) => {
    let itemId = request.body._id;
    ExpenseAndAmountTemplate.findByIdAndRemove(itemId, function(err){
        if(err){
            response.send("/Could not delete the item...");
        } else {
            response.send("/Expenses and amount item was deleted succesfully...");
        }
     });
 });

ExpenseAndAmountModel.js (This is the model used at router.delete)

const mongoose = require('mongoose');

const ExpenseAndAmountTemplate = new mongoose.Schema({
    _id: {
        type:String,
        required:false
    },
    expenseTitle: {
        type:String,
        required:true
    },
    expenseAmount: {
        type:String,
        required:true
    }
});

module.exports = mongoose.model('ExpenseAndAmountData', ExpenseAndAmountTemplate);

Do you know how to solve it? Thanks!

Cheetha

Instead of { itemId: toBeDeletedItemId } try { data: { itemId: toBeDeletedItemId } }

This way you are passing data to the request body.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Argument of type '{ params: object; }' is not assignable to parameter of type 'AxiosRequestConfig<any>'

Typescript error 'argument of type is not assignable to parameter of type'

typescript error: argument type is not assignable to parameter of type

Argument of type is not assignable to parameter of type Typescript Error

Getting an error Argument of type 'unknown' is not assignable to parameter of type 'Error | null'

Argument of type is not assignable to parameter of type

Typescript error: Argument of type 'Object' is not assignable to parameter of type '{}[]'

TypeScript: Argument of type '(error: any) => void' is not assignable to parameter of type

Typescript error on React Component: Argument of type 'Element' is not assignable to parameter of type

getting error : Argument of type '() => () => boolean' is not assignable to parameter of type 'EffectCallback'

Typescript enums typing error (argument of type 'string' is not assignable to parameter of type)

Confusing compiler error: Argument of type 'string' is not assignable to parameter of type

How to fix Argument of type '"email"' is not assignable to parameter of type 'string[]' error?

How to fix "Argument of type ... is not assignable to parameter of type ..." error?

CombineReducers with Typescript returns error "Argument of type is not assignable to parameter of type 'ReducersMapObject'"

error TS2345: Argument of type 'Menu' is not assignable to parameter of type

Argument of type X is not assignable to parameter of type X error in Angular 7

Typescript error: Argument of Type X is not assignable to parameter of type Y

argument of type string | null is not assignable to parameter of type string error

Typescript Error Argument of type 'string | number' is not assignable to parameter of type 'never'

Getting Error: Argument of type 'number' is not assignable to parameter of type 'string'

Getting error as Argument of type '{ headers: HttpHeaders; }' is not assignable to parameter of type 'HttpParamsOptions'

Typescript, useContext(), error: Argument of type 'never[]' is not assignable to parameter of type

Getting the error: Argument of type {JSON Object} is not assignable to the parameter of 'never'

error: [dart] The argument type 'Context' can't be assigned to the parameter type 'BuildContext'. [argument_type_not_assignable]

Error "Argument of type '{}' is not assignable to parameter of type 'T | (() => T)'" in a React component with a type parameter

Argument of type '{}' is not assignable to parameter of type in Angular 8

Argument of type numbering is not assignable to parameter of type string

Argument of type is not assignable to parameter of type 'string'