title: Angular 6 and Angular Material Mat table dataSource Argument of type 'Object' is not assignable to parameter of type '{}[]'
body: <p>I am getting a list of users from a MySQL database to display it in <code>&lt;mat-table&gt;</code> using the <code>dataSource</code> property:</p>
  <p>The following is the TypeScript method <code>getUnitData()</code>, where I am setting the dataSource value as the returned JSON array from PHP script:</p>
  <pre class="lang-js prettyprint-override"><code>export class RegistrationComponent implements OnInit {
    dataSource: MatTableDataSource&lt;units&gt;;
  
    @ViewChild(MatPaginator) paginator: MatPaginator;
    @ViewChild(MatSort) sort: MatSort;
    constructor(private auth: AuthApiService) { }
  
    ngOnInit() {
      this.dataSource.paginator = this.paginator;
      this.dataSource.sort = this.sort;
    }
  
    applyFilter(filterValue: string){
      this.dataSource.filter = filterValue.trim().toLowerCase();
  
      if(this.dataSource.paginator)
      {
        this.dataSource.paginator.firstPage();
      }
    }
  
    getUnitData(){
      this.auth.getUnitDataService().subscribe(
        (data)=&gt;
        {
          this.dataSource = new MatTableDataSource(data);
        },
        (error)=&gt;
        {
  
        }
      )
    }
  
  }
  </code></pre>
  <p>And here is the main method from the <code>AuthApiService</code>:</p>
  <pre class="lang-js prettyprint-override"><code>getUnitDataService(){
      if(this.checkIsLogin){
        this.headerOptions.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
  
        return this.http.get(this.globalVar.getUnitData,{
          headers: this.headerOptions
        });
      }
      else{
        this.router.navigate(['/login']);
      }
    }
  </code></pre>
  <p>The PHP script is:</p>
  <pre class="lang-php prettyprint-override"><code>public function getUnitData($conn)
  {
      try{
          $sql = &quot;SELECT * FROM unit ORDER BY unit_id DESC&quot;;
          $getData = $this-&gt;conn-&gt;prepare($sql);
          $getDataResult = $getData-&gt;execute();
          $getDataSize = $getDataResult-&gt;rowCount();
          $getDataResult-&gt;fetchAll();
  
          return $getDataResult;
      }
      catch(PDOException $e)
      {
          echo $e-&gt;getMessage();
      }
  }
  </code></pre>
  <p>And then I am calling in another file using the following URL: <code>this.globalVar.getUnitData</code>.</p>
  <p>The errors I am getting is as the following:</p>
  <p><strong>1.</strong></p>
  <blockquote>
  <p>[ts] Cannot find name 'units'.</p>
  </blockquote>
  <p><strong>2.</strong></p>
  <blockquote>
  <p>Argument of type 'Object' is not assignable to parameter of type
  'any[]'.   The 'Object' type is assignable to very few other types.
  Did you mean to use the 'any' type instead?
  Property 'length' is missing in type 'Object'.</p>
  </blockquote>
  <p>I tried <a href="https://stackoverflow.com/questions/48085153/typescript-error-argument-of-type-object-is-not-assignable-to-parameter-of-ty?answertab=active#tab-top">this solution</a> on Stack Overflow, but still I get the same error.</p>