Angular 12 – is not assignable to type '[number, number]


I am trying out ngx-charts library in Angular 12 and I keep getting this issue:

Type ‘any[]’ is not assignable to type ‘[number, number]’.

Target requires 2 element(s) but source may have fewer.

I don’t know what the error means.

Here is the code:




import { Component } from '@angular/core';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
export class AppComponent {

  single: any[];
  view: any[] = [400, 400];
  colorScheme = {
    domain: ['#aae3f5']
  value: number = 43;
  previousValue: number = 70;
  units: string = 'counts';

  onSelect(event) {


Any ideas on what the error means, how to fix this?

ts config code is:

  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2017",
    "module": "es2020",
    "lib": [
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true


I guess the issue is the type of you view property. According to the cods it must be of type number[]: doc-ref
note: the type in the docs is not exact enough. view is not defined as array of number (number[]), but as a tuple of 2 numbers ([number, number]) – source-code ref

But you define it as any[].
Depending on your typescript compiler settings, you may get an error or warning.

When you need the exact correct type use:

// use as const so that typescript will infer the type [number, number] instead of number[]
view = [400, 400] as const;

The explict type would be:

view: [number, number] = [400, 400];

Answered By – TmTron

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published