This is typescript. I keep getting this error Parameter 'x' implicitly has an 'any' type, but a better type may be inferred from usage.ts(7044) .
class mycalculation {
x: number = 1;
y: number;
add(x, y) {
return x + y;
}
}
const mycal = new mycalculation();
const output = mycal.add(1,2);
I keep getting this error
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new typescript file with name "samp.ts" is created, which contains following code.
samp.ts :
//class
class mycalculation {
x: number = 1;
y: number;
add(x, y) { //function
return x + y;
}
}
//object of class
const mycal = new mycalculation();
//call method with class object
const output = mycal.add(1,2);
console.log("Adition is "+output);//print output
======================================================
Output : Compile and Run samp.ts to get the screen as shown below
Screen 1 :samp.ts
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.
Get Answers For Free
Most questions answered within 1 hours.