The 'children' property is not found in the type 'ColDef<object>' in <AG-Grid>

Currently working on a project involving AG grid, but encountering an issue with TypeScript. The error message states ([AG-Grid] Property 'children' does not exist on type 'ColDef') and it appears when using the filter method around (column => column.children).

After referring to the AG-Grid documentation, it seems that column defs do support using children as a property. So why am I receiving this error?

https://i.sstatic.net/9GTmE.png

import { ColDef, ColGroupDef } from 'ag-grid-community';

export const sampleItems: Array<{
  label: string;
  value: string;
}> = [];

export const TABLE_COLUMN = [
  {
    headerName: 'User',
    children: [
      {
        field: 'user',
        headerName: 'Name',
        pinned: 'left',
        type: 'fixed',
      },
      { field: 'account', pinned: 'left', type: 'fixed' },
      {
        field: 'price',
        headerName: 'Pricing',
        pinned: 'left',
        type: 'primary',
      },
    ],
  },
  {
    headerName: 'Address',
    children: [
      { field: 'address', headerName: 'Address', type: 'secondary' },
      {
        field: 'street',
        headerName: 'Street Name',
        columnGroupShow: 'closed',
        type: 'secondary',
      },
    ],
  },
] as (ColDef<object> | ColGroupDef<object>)[];


TABLE_COLUMN.filter((column) => column.children != null).forEach(
  (column) => {
    column.children.forEach((child) => {
      if (child.type === 'fixed' || child.type === 'primary') {
        sampleItems.push({
          label:
            child.headerName ??
            child.field.charAt(0).toUpperCase() + child.field.slice(1),
          value: child.field,
        });
      }
    });
  },
);

Answer №1

Modify the approach. We are informing TypeScript that it will be a colGroupDef, so there is no need to validate for the ColDef type.

 (<ColGroupDef<object>>TABLE_COLUMN).filter((column: ColGroupDef<object>) => column.children != null).forEach(
  (column: ColGroupDef<object>) => {
    column.children.forEach((child: ColDef<object>) => {
      if (child.type === 'fixed' || child.type === 'primary') {
        sampleItems.push({
          label:
            child.headerName ??
            child.field.charAt(0).toUpperCase() + child.field.slice(1),
          value: child.field,
        });
      }
    });
  },
);

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

Accessing a file from a Docker volume within an Angular project using Typescript

Managing data between Angular and NodeJS containers can be tricky. In my setup, I have separate containers for each, with NodeJS writing data to a file stored in a Docker Shared volume. To access the file from NodeJS within the shared volume, I use the fo ...

When there are multiple tabs open in the browser, I notice a difference in the time displayed. This occurs in an Angular 2 environment

https://i.sstatic.net/l4YQ1.pngAfter a successful login, I am fetching server time from the back-end (in Java) and adding 1 second at intervals. Observable.interval(1000).map(() => { return this.time.add(1, 'seconds'); }). ...

Instructions on relocating a rectangle and capturing its coordinates globally for cropping the chosen image

I am currently a software engineering trainee, focusing on learning Angular CLI. My current project involves image cropping on a canvas, where I draw a circle when clicked. My query pertains to moving the circle with a mousedown event and stopping it upon ...

What is the best way to convert an array of Firestore DocumentReferences into an array of DocumentData?

Trying to create a Google Cloud Function that reads Firestore Documents from a collection and takes action based on these documents. The goal is to optimize efficiency by reading the documents once and storing them in an array to minimize read operations. ...

What are some methods for retrieving RTK Query data beyond the confines of a component?

In my React Typescript app using RTK Query, I am working on implementing custom selectors. However, I need to fetch data from another endpoint to achieve this: store.dispatch(userApiSlice.endpoints.check.initiate(undefined)) const data = userApiSlice.endpo ...

Tips for adding and verifying arrays within forms using Angular2

Within my JavaScript model, this.profile, there exists a property named emails. This property is an array composed of objects with the properties {email, isDefault, status}. Following this, I proceed to define it as shown below: this.profileForm = this ...

What measures can I take to address the TypeScript error indicating that my function is missing a return statement and the return type does not include 'undefined' in my code?

In this scenario, there is a straightforward function called make which utilizes the handle function to retry a specified number of times if it encounters an error. Once all retries have been exhausted, the make function should throw the error. const handl ...

Refresh the mapbox source features in real-time

Currently, I am mapping out orders on a map with layers and symbols that have different statuses. When the status of an order changes, I want to update the color of the symbol accordingly. The layer configuration looks like this: map.addLayer({ id: &q ...

How about using take(1) in conjunction with an Observable<boolean>?

After going through this insightful article, I came across the following implementation of a CanActivate check to determine whether the user can navigate to the home page: canActivate(): Observable<boolean> { return this.authQuery.isLoggedIn$.pipe( ...

The unexpected identifier 'express' was encountered in the import call, which requires either one or two arguments

I'm in the process of constructing an express server using typescript and Bun. Recently, I completed my register route: import express from "express"; const router = express.Router(); router.get('/registerUser',(_req:express.Reque ...

Using useState to initialize a long value

Obtaining a very large state from JSON can be challenging, especially when it consists of at least 50 lines. During page generation, an error like "there is no such value" may occur if the initial value is not set and the interface is not assigned properl ...

What is the best way to compare an array with comma-separated values in JavaScript?

I have a scenario where I have two arrays, one for categories and the other for products. Each product contains multiple categories as a comma-separated string. My goal is to match a specific category with each product's product_category value and the ...

Why are my class data types not aligning with JSON objects?

In my Node.js project using TypeScript, I have defined the Tariff and Tariffs classes. I also generated fake data in JSON format that should align with these Classes. However, I encountered an error in the resolve() method stating: Argument of type &apo ...

Exploring how enums can be utilized to store categories in Angular applications

My application has enums for category names on both the back- and front-end: export enum CategoryEnum { All = 'All', Category1 = 'Category1', Category2 = 'Category2', Category3 = 'Category3', Cate ...

What is the process of transforming a Firebase Query Snapshot into a new object?

Within this method, I am accessing a document from a Firebase collection. I have successfully identified the necessary values to be returned when getUserByUserId() is invoked, but now I require these values to be structured within a User object: getUserB ...

Encountering difficulty in establishing a global variable within the subscribe function

I am looking to store the service response in a variable for use in my view. The TypeScript file I am working with is shown below: The MenuService is a custom service that includes a function called getMenus() to fetch all menus from the database. import ...

Encountering build issues in my next.js application post updating to version 12.#.# and implementing Typescript

In my next.js application, I recently upgraded to version 10 and added TypeScript to the mix. Despite ironing out all issues during development, I encountered errors when running yarn next build due to my use of the keyword interface. ./src/components/ ...

Showing identification and name within a URL path - Angular

I am looking to update a URL path within a website from http://localhost:4200/viewbrand/1 to http://localhost:4200/viewbrand/1/soap, where "soap" is added after the ID in the path. The current code in the routing module.ts file is as follows: { path: &apo ...

Guide on changing the background image of an active thumbnail in an autosliding carousel

My query consists of three parts. Any assistance in solving this JS problem would be highly appreciated as I am learning and understanding JS through trial and error. https://i.sstatic.net/0Liqi.jpg I have designed a visually appealing travel landing pag ...

In Chrome's developer tools, there's an interesting quirk where variables may be displayed as undefined, yet the tool

Having some trouble adequately explaining and defining the issue at hand, I can only pinpoint it occurring in Chrome DevTools, with the code compiled using Parcel and TypeScript version 4.4 or higher. Specifically, I'm observing an issue a few lines ...