tochoromero / aurelia-table

Simple functional data table for Aurelia
https://tochoromero.github.com/aurelia-table
MIT License
67 stars 25 forks source link

rror TS2322: Type 'Response' is not assignable to type 'any[]'. #50

Closed BretMishler closed 6 years ago

BretMishler commented 6 years ago

I'm following the exact same code in the documentation for the basic example.

import {HttpClient} from "aurelia-fetch-client";

export class Example {
    users = [];

    bind(){
        let client = new HttpClient();

        return client.fetch('data.json')
            .then(response => response.json())
            .then(users => this.users = users);
    }
}

Yet I get Gulp and console errors, and my project will not run successfully.

Gulp: error TS2322: Type 'Response' is not assignable to type 'any[]'. Browser Console: GET http://localhost:44336/dist/main.js?bust=1508431998767 Error: XHR error (404) loading https://localhost:44336/main.js?bust=1508431998767 Error loading https://localhost:44336/dist/main.js

The 404 error makes it obvious that some file is missing BUT:

When I comment out the return client.fetch code block (from above) and run the project, the XHR error never logs to the console. So with my project open and running, I navigate to the page where my table is, go back into my IDE to comment the code block back in then go back to the browser to flush the page cache and refresh the page- the XHR error doesn't appear in the logs and the data from my data.json page loads just fine.

BretMishler commented 6 years ago

Asked this on SO and a user there solved it:

then((users:any) => this.users = users

Maybe it wasn't required when the Aurelia-Table docs were written but there needs to be an explicit conversion from type Response to any.