Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error TS1248: A class member cannot have the 'const' keyword.[];

Tags:

angular

I am working on angular 2 MEAN application development. I am facing below issue

error TS1248: A class member cannot have the 'const' keyword.[];

I have declared below const array. I want to use this array to any function where I need.

const ballmasterObj: Array<any> = [];

I have a function which updates this array for ex. code below.

var obj= {};
      obj.ovrnum= "2";
      obj['balls']=[];
      var ballObj = {};
      ballObj['balllN'] = "4";
      ballObj['key'] = "3380dkasfka";
      obj['balls'].push(ballObj);

this.ballmasterObj.push(obj);

This individual obj is in a loop to push individual objects to master obj which is array.

I can understand from error that I cannot have a const keyword in class. I am new to typescript and angular 2 as well.

I have looked up for the issue on google search but did not come to any conclusion.

like image 727
Akki619 Avatar asked Apr 30 '18 06:04

Akki619


People also ask

How to solve the error “a class member cannot have the “const” keyword?

The error "A class member cannot have the 'const' keyword" occurs when we use the const keyword to declare a property in a class. To solve the error, remove the const keyword and use the readonly modifier to indicate that a class property should not be changed. Here is an example of how the error occurs.

What is error ts1248 in angular?

angular - error TS1248: A class member cannot have the 'const' keyword.[]; - Stack Overflow I am working on angular 2 MEAN application development. I am facing below issue error TS1248: A class member cannot have the 'const' keyword.[];

Can a class member have the 'const' keyword in JavaScript?

a class member cannot have the 'const' keyword. ts1248: a class member cannot have the 'const' keyword. 3. What are private member variables. in js Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6.

Can a class member have the 'const' keyword in angular?

A class member cannot have the 'const' keyword. angular An accessor cannot be declared in an ambient context. a class member cannot have the 'const' keyword. ts1248: a class member cannot have the 'const' keyword. 3. What are private member variables. in js


1 Answers

You do not have to have const when you declare it, this should do

ballmasterObj: Array<any> = [];

however if you really want to have a const value in your class, TypeScript 2.0 has the readonly modifier

like image 182
Sajeetharan Avatar answered Oct 23 '22 01:10

Sajeetharan