The type of "never" cannot be assigned to a promise, an array, a boolean, or an

I have identified the data type I am receiving from the server action, yet an error persists indicating that it cannot be assigned to a type that does not exist.

type Package = {
    productName: string;
  };
  
  type BuddyShield = {
    remarks: string | null;
    buddyShieldUploadProof: boolean;
    rtoStarted: Date | null;
  };
  
  type User = {
    fullname: string;
  };
  
  export type OrderSecondSchema = {
    id: number;
    awbNumber: string | null;
    ChannelOrder_Id: string | null;
    deliveryPartner: string | null;
    shippingDate: Date;
    status: OrderStatus;
    Packages: Package[];
    buddyShield: BuddyShield | null;
    Users: User;
  };
  
  export type OrderQueryResult = OrderSecondSchema[];

  export async function getFilteredOrders(filters: OrderFilters)  {
    const { startDate, endDate, partner, page, searchQuery } = filters;
    const itemsPerPage = 10;
    const skip = (page - 1) * itemsPerPage;

    const userIdString = getCurrentUser();

> userIdString, gets the string id.

    const whereClause: any = {
      status: {
        in: ['RTO_IN_TRANSIT', 'RTO_DELIVERED']
      }
    }

    whereClause.usersId = userIdString

    const allOrders : OrderQueryResult = await prisma.orders.findMany({
      where: whereClause,
      select: {
        id: true,
        awbNumber: true,
        ChannelOrder_Id: true,
        deliveryPartner: true,
        shippingDate: true,
        status: true,
        Packages : {
         select: {
          productName: true,
         }
        },
        buddyShield : {
          select: {
            remarks: true,
            buddyShieldUploadProof: true,
            rtoStarted: true,
          }
        },
        Users: {
          select: {
            fullname: true,
          }
        },
      }
    });

    // console.log('Line 81 ', allOrders);
  
    // Apply date and partner filters
    console.log('Line 122 startdate ', startDate, ' enddate ', endDate);
    let filteredOrders = allOrders.filter((order) => {
      const orderDate = new Date(order.shippingDate);
      const dateFilter = 
        (!startDate || orderDate >= new Date(startDate)) &&
        (!endDate || orderDate <= new Date(endDate));
        const partnerFilter = 
        partner === "All" || 
        (order.deliveryPartner?.toLowerCase() ?? "") === partner.toLowerCase();
      return dateFilter && partnerFilter;
    });
  
  
    // Apply fuzzy search if searchQuery is provided
    if (searchQuery) {
      console.log('Line 137 ', searchQuery);
      const fuse = new Fuse(filteredOrders, {
        keys: ['awbNumber'],
        threshold: 0.3,
      });
      filteredOrders = fuse.search(searchQuery).map(result => result.item);
      console.log('Fuse Search ', filteredOrders);
    }
  
    const totalOrders = filteredOrders.length;
    const totalPages = Math.ceil(totalOrders / itemsPerPage);
  
    // Apply pagination
    filteredOrders = filteredOrders.slice(skip, skip + itemsPerPage);
  
    return {
      orders: filteredOrders,
      totalPages,
      currentPage: page,
      totalOrders,
    };
  }

I attempted to define types specifying the expected return values and checked the line number where the error occurred to determine if it was related to the type or not, but unfortunately, I could not resolve it.

Answer №1

Encountered an issue with server actions BuddyShield and HighShipping. In both folders, BuddyShield and HighShipping, the file page.tsx was causing a problem due to not naming the file correctly in server actions. Renaming the file to anything other than page.tsx resolved the type error.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Changing the names of the remaining variables while object destructuring in TypeScript

UPDATE: I have created an issue regarding this topic on github: https://github.com/Microsoft/TypeScript/issues/21265 It appears that the syntax { ...other: xother } is not valid in JavaScript or TypeScript, and should not compile. Initial Query: C ...

The unique error message E11000 occurred due to a duplicate key in the collection test.products, specifically in the index called name_1 with the key value of { name: "

When a logged-in user wants to purchase a specific product, I need to send a POST request to save the product in the basket. Then, I need to retrieve it using a GET request to display and further manipulate it. However, I am encountering an issue with this ...

The dynamic duo of MongoDB and Prisma: forging a groundbreaking one-to-many relationship

Is it possible to establish a one-way m-to-n relationship without requiring both collections to have each other's ids? I am attempting the following: model Country { id String @id @default(auto()) @map("_id") @db.ObjectId ...

What is the best way to fetch the id of the option that has been chosen from a bootstrap drop-down menu?

I recently created a basic drop-down list like this: https://i.sstatic.net/4Tlxx.png Here is the HTML code for it: <select class="form-control" id='0' (change)="retrieveValue($event.target)"> <option id='0'>{{ g ...

The deployment of a Next JS 13 app to Azure Static Web Apps is facing challenges and cannot

I'm encountering a 500 error when attempting to deploy my upcoming 13 app directory application to Azure Static Web Apps. Despite checking Azure for logs and exploring the Diagnose tab, I am unable to find any information. Here is an excerpt from my w ...

How can you load an HTML page in Puppeteer without any CSS, JS, fonts, or images?

My current task involves using Puppeteer to scrape data from multiple pages in a short amount of time. However, upon closer inspection, I realized that the process is not as efficient as I would like it to be. This is because I am only interested in spec ...

Changing background color during drag and drop in Angular 2: A step-by-step guide

A drag and drop container has been created using Angular 2 typescript. The goal is to alter the background color of the drag & drop container while dragging a file into it. Typescript: @HostListener('dragover', ['$event']) public onDr ...

Exploring Cypress: Leveraging the Power of Variable Assignment

Recently, I encountered an issue while working with a variable in a Cypress each loop. Despite incrementing the variable within the loop, it resets to zero once outside of it. Can someone shed light on why this happens and suggest a solution? Thank you. p ...

What is the proper way to define and update a variable within a React Class Component in order to maintain a reference to a setTimeout function

Having primarily worked with React function components, my typical approach is to declare consts inside the function. However, I recently encountered a situation where I needed to declare a variable in a class component, and I experimented with three diffe ...

Simulating a winston logger in jest testing

I am pondering how to create mock transports for the File module within the Winston node package. While utilizing Jest, the __mocks__/winston.ts file is automatically loaded. My dilemma lies in the fact that I am unable to mock it due to the presence of th ...

Exploring end-to-end testing with NestJS and Guards

I'm trying to test an endpoint called /users using nestjs, but I encountered some errors. I'm unsure how to fix the issues and make the test pass with a guard. First Issue Nest is unable to resolve dependencies of the UserModel (?). Please en ...

Is there a way to toggle a single Reactstrap Collapse component?

Currently, I am working on a Next.JS application that displays a list of Github users. The goal is to have each user's information box toggle open and close when clicked, using Reactstrap's Collapse component. However, the issue I'm facing i ...

Despite Typescript Errors, Turbo Repo Continues to Generate Builds

In my turborepo monorepo, the structure looks like this: apps |- app1 |- app2 packages |- lib | .... some files |- tsconfig.json |- package.json Within the lib directory, I intentionally included a file with an obvious error. The editor correctl ...

Always ensure that the state is correctly updated before displaying any information in a React Modal component

I am currently utilizing a combination of Material-UI components, the useState hook, and the NextJS framework. Within my render method, I am mapping over someData where each element has the following structure: someData[i] : { "id": number, ...

Retrieving a specific value from a collection of nested arrays containing objects

Having trouble extracting values from fields and have tried various methods like nesting the map function and concatenating fields without success. I have an object with a structure similar to this: [{ name: 'sean', age: 26, address: ...

What is the best way to retrieve entire (selected) objects from a multiselect feature in Angular?

I'm facing an issue with extracting entire objects from a multiselect dropdown that I have included in my angular template. Although I am able to successfully retrieve IDs, I am struggling to fetch the complete object. Instead, in the console, it dis ...

What is the best way to generate a dynamic HTML page output in Next.js?

Is there a way to generate a dynamic page in Next.js with HTML output? I have a dynamic page that doesn't create a file after export. When clicking on the links, the page loads, but upon refreshing a 404 error is displayed. Can dynamic page links be d ...

Holding an element in TypeScript Angular2 proved to be challenging due to an error encountered during the process

I attempted to access a div element in my HTML using ElementRef, document, and $('#ID') but unfortunately, it did not work. I tried implementing this in ngOnInit, ngAfterViewInit, and even in my constructor. Another method I tried was using @Vie ...

What's the deal with integrating Supabase sessions into NextJS SSR/SGR?

Is it feasible to integrate Supabase with both server-side and client-side rendering simultaneously? It appears that typically we must opt for one or the other, but NextJS offers the flexibility to define SSG (server-side generated), SSR (server-side rende ...

Encountering errors while initiating a project using Express and NestJS

While working on my nestJS project, I encountered an error upon starting the project. Could this be due to an issue with the @types/express package? Or perhaps it's something that I have configured incorrectly? Any insights or tips would be greatly ap ...