Angular7 Error: Argument of type x is not assignable to parameter of type x

Last Reply 26 days ago By dharmendr

Posted 27 days ago

Hi, I am very new to Angular 7. I am facing errors in below line of code. Please someone let me know what is wrong in my code. Any help would be appreciated. Thank you in advance.

var x1 = 10, x2 = 100, x3 = datar.map(function (item) { return [ item.xmax ] })
        .reduce(function(a, b) { return Math.max(a, b); });
    var y1 = 10, y2 = 100, y3 = datar.map(function (item) { return [ item.ymax ] })
        .reduce(function(a, b) { return Math.max(a, b); });

In above code I get error: Argument of type 'number[]' is not assignable to parameter of type 'number' at 'a, b' in code 'return Math.max(a, b)'

var data = [ [0,0,0],[0,1,4],[0,2,1],[0,3,1]
                ,[1,0,0],[1,1,9],[1,2,4],[1,3,1]
                ,[2,0,0],[2,1,9],[2,2,9],[2,3,9]
                ,[3,0,0],[3,1,0],[3,2,0],[3,3,0] ];
     
    data = data.map(function (item) {
        return [item[1], item[0], item[2] || '-'];
    });

In above code I get error: Type '(string | number)[][]' is not assignable to type 'number[][]'. Type '(string | number)[]' is not assignable to type 'number[]'. Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number' at 'data'

var objseries = datar.map(function(x) {
       return {
            type: 'scatter',
            symbol: 'diamond',
            symbolSize: 10,
            itemStyle:{
                normal:{ 
                    color:  x.color
                }
            },
            data: x.data.map(function (item) {
                return [
                item[0] <= x1 ? 0 + ((item[0] - 0) / ((x1 - 0) / 100)) / 100 :
                (item[0] <= x2 ? 1 + ((item[0] - x1) / ((x2 - x1) / 100)) / 100 :
                (item[0] <= x3 ? 2 + ((item[0] - x2) / ((x3 - x2) / 100)) / 100  : 2)),
               
                item[1] <= y1 ? 0 + ((item[1] - 0) / ((y1 - 0) / 100)) / 100 :
                (item[1] <= y2 ? 1 + ((item[1] - y1) / ((y2 - y1) / 100)) / 100 :
                (item[1] <= y3 ? 2 + ((item[1] - y2) / ((y3 - y2) / 100)) / 100  : 2)),
               
                item[0], item[1]
                ];
            }),
        }
    });

In above code I get error: Operator '<=' cannot be applied to types 'number' and 'number[]' at 'item[0] <= x3' in code 'item[0] <= x3 ? 2 + ((item[0] - x2) / ((x3 - x2) / 100)) / 100 : 2))' <br/> and<br/> The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type at x3 in code '(x3-x2)'

Posted 27 days ago
Richa12 says:
 return [item[1], item[0], item[2] || '-'];

Please check the above line of code.

You are assigning string value in the or condition which expects integer value.


Posted 27 days ago

I have fixed mentioned errors but now I am facing another(described below) typescript error:

Type '(string | number)[][]' is not assignable to type 'number[][]'.
  Type '(string | number)[]' is not assignable to type 'number[]'.
    Type 'string | number' is not assignable to type 'number'.
      Type 'string' is not assignable to type 'number'.ts(2322)
chart.component.ts(77, 13): The expected type comes from property 'data' which is declared here on type '{ type: string; symbol: string; symbolSize: number; itemStyle: { normal: { color: string; }; }; data: number[][]; }'

Code:

var datar = [
	{
		name: 'TEST-A',
		data: [
			[4,4],[25,4],[700,4],[4,40],[25,40],[160,40]
		],
		xmax: 700,
		ymax: 40,
		color: 'purple',
	},
	{
		name: 'TEST-B',
		data: [
			[10.0, 8.04],
			[8.0, 6.95],
			[13.0, 7.58],
			[9.0, 8.81],
		xmax: 160,
		ymax: 400,
		color: 'green',
	}
];

var objseries = datar.map(function(x) {
   return {
		type: 'scatter',
		symbol: 'diamond',
		symbolSize: 10,
		itemStyle:{
			normal:{ 
				color:  x.color
			}
		},
		data: x.data.map(function (item) {
			return [
			item[0] <= x1 ? 0 + ((item[0] - 0) / ((x1 - 0) / 100)) / 100 :
			(item[0] <= x2 ? 1 + ((item[0] - x1) / ((x2 - x1) / 100)) / 100 :
			(item[0] <= x3 ? 2 + ((item[0] - x2) / ((x3 - x2) / 100)) / 100  : 2)),
		   
			item[1] <= y1 ? 0 + ((item[1] - 0) / ((y1 - 0) / 100)) / 100 :
			(item[1] <= y2 ? 1 + ((item[1] - y1) / ((y2 - y1) / 100)) / 100 :
			(item[1] <= y3 ? 2 + ((item[1] - y2) / ((y3 - y2) / 100)) / 100  : 2)),
		   
			item[0], item[1]
			];
		}),
	}
}); 
    
objseries.splice(0, 0, {
	name: 'Severe Moderate Mild',
	xAxisIndex : 1,
	yAxisIndex : 1,
	type: 'heatmap',
	data: data, //error here
	label: {
		normal: {
			show: false
		}
	}
});

This code will then go and sit in 'series' property ofhttps://echarts.apache.org/examples/en/editor.html?c=doc-example/scatter-visualMap-categories&edit=1&reset=1 (this link is just for example to explain the relation)

Kindly let me know how to fix this. I am stuck at this point to commit my changes. Thank you so much in advance