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.
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.
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.[];
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With