Is it possible for abstract classes to utilize arrays?

Can you have an array inside an abstract class in TypeScript and add items to it?

abstract class Department {
  private data: string[] = [];

  addData(item: string) {
    this.data.push(item);
  }

  constructor(public name: string) {}

  printName(): void {
    console.log("Department name: " + this.name);
  }

  abstract printMeeting(): void;
} 

Answer №1

Absolutely, that is possible to do. The process is very similar to doing it in a regular class, you simply need to designate it as abstract:

abstract class Example {
    private data: string[] = [];

    addData(item: string) {
        this.data.push(item);
    }
}

However, keep in mind that this will only be beneficial if you create a subclass of it (

class SomethingElse extends Example
...).

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

Leveraging TypeScript to sort and extract specific elements from two arrays

Given two arrays, I am looking to identify the elements in array2 that match elements in array1 based on a specific property. The arrays are structured as follows: var array1 = [ {"myId": 1, "text": "a"}, {"myId& ...

Exploring jQuery's Array Iteration Feature

Is there a way to create Custom Lists with a User-Friendly approach? For example: var unitA = []; unitA[0] = "Unit A One"; unitA[1] = "Unit A Two"; unitA[2] = "Unit A Three"; var unitB = []; unitB[0] = "Unit B One"; unitB[1] = "Unit B Two"; unitB[2] = " ...

Is it possible to harness the power of a Typescript array within my HTML while incorporating primeng chips?

My subject line brings up a question: How can I transform the following piece of HTML code? HTML <p-chip label="1 day(s)" styleClass="p-mb-2 p-mr-2 custom-chip"></p-chip> <p-chip label="2 day(s)" styleClass=&qu ...

What is the best way to send an observable with parameters through @Input?

The objective is to transfer an http request from Component 1 to Component 2 and initialize its parameters on Component 2. Here is a pseudo code representation of my approach: Component 1 HTML <app-component-2 [obs]="obs"></app-component-1> ...

I'm looking for a way to convert an array value to JSON using jQuery

i need assistance in converting an array value into json format. An example is provided below: Sample Array [Management Portal!@!@Production Issue Handling!@!@/IONSWeb/refDataManagement/searchDynamicScripts.do, Management Portal!@!@ Event Browser!@!@/ION ...

What is the best way to put into practice a Calendar system?

What is the best way to integrate a Calendar in Angular2 using typescript? Are there any specific directives that need to be imported? ...

What is the process of converting a byte array into a blob using JavaScript specifically for Angular?

When I receive an excel file from the backend as a byte array, my goal is to convert it into a blob and then save it as a file. Below is the code snippet that demonstrates how I achieve this: this.getFile().subscribe((response) => { const byteArra ...

Choose a file in React by specifying its path instead of manually picking a file

Is there a way for me to automatically select a file from a specified path into my state variable without having to open a select file dialog? I'm looking for a solution where I can bypass the manual selection process. Any suggestions on how this can ...

Procedure for obtaining the Cartesian product

Seeking help with finding Cartesian product in C++. Here is the input array: [0, 2, 3, 0, 1] And the expected output: [0, 0, 0, 0, 0] [0, 0, 0, 0, 1] [0, 0, 1, 0, 0] [0, 0, 1, 0, 1] [0, 0, 2, 0, 0] [0, 0, 2, 0, 1] [0, 0, 3, 0, 0] [0, 0, 3, 0, 1] [0, 1, ...

My struggle lies in understanding how array pointers work within functions in C++

I'm interested in learning about pointers and how to use them effectively. To better understand how arrays work, I decided to create a script that mimics Python's len() function. Here is the code I came up with: int len(int *arrPtr){ int arr ...

JavaScript array error - unrecognized symbol

Hello, I am attempting to generate an array of errors and showcase them all at once. Here is my code: if (!first_name) { var error[] = "Please fill in the Last Name"; $('#first_name').addClass('error'); } else { $('#fi ...

What is the best way to simulate a TypeScript enum in my Jest test suite?

In my unit tests, I need to create a mock of an enum. The original enum structure includes fixed values for 'START' and 'END', but the middle options can change over time to represent new features. These changes may involve adding or re ...

Creating a collection of arrays that are named based on the properties of an object

After calling an ajax service, I received a collection of objects where Object (A) properties are Group, order, salary. For example, the objects could be [Employee, 1, 1500],[Management, 2, 2000], [Employee, 3, salary]. My task is to create an array for e ...

Angular 18 mysteriously generating a fake routing error, even though the routes were functioning perfectly before

Issue: I've been working on integrating a login component with Google authentication in my Angular application. The user information is retrieved upon successful authentication, a token is generated, and then sent to the backend for further processing ...

Can 2D hexagonal arrays be generated similar to square arrays in Python?

Is it within the realm of possibility to generate a 2D hexagonal array in Python where the elements are positioned at the vertices of the hexagons? Similar to a 2D square array using NumPy, where the square's corners correspond to the array elements. ...

Using a Typescript Class Decorator to Enhance Functionality

Can anyone help me implement a timing decorator for my Typescript classes similar to what is commonly used with Python? Consider the following example class class MyClass() { private _foo: string = 'abc'; public printX() : void { conso ...

Utilizing a function to pass an Array

// The following code showcases the passing of an array to a function in C++. #include <iostream> using namespace std; void displayArrayValues(int [], int); // Function prototype int main() { const int ARRAY_SIZE = 8; int numbers[ARRAY_SIZ ...

Changing the mouse cursor dynamically with Angular programming

What is the recommended approach for changing the mouse cursor programmatically in Angular? For instance: HTML: <div [style.cursor]="cursorStyle">Content goes here</div> or <div [ngStyle]="{ 'cursor': cursorStyle ...

Add a unique class to an element within a main component

Within our application root, there exists a sidebar consisting of a list. We utilize uiSrefActive to apply an active class to the selected list item upon clicking it. However, once you navigate away from that component, the original list item loses its a ...

The function QUERY encountered an error while trying to parse the query string. It ran into a problem at column 2168

Previously, my formula worked perfectly fine. However, after adding more data to my master table where 'Premium Advertisers' is populated, I started receiving the following error: "Unable to parse query string for Function QUERY parameter 2: PAR ...