microsoft/SimpleRestClients

Type 'Promise<T>' is not assignable to type 'Promise<T>'. Two different types with this name exist, but they are unrelated.

rbravo opened this issue · 2 comments

Hi, I'm trying to run a simple REST client but I'm getting this error on VSCode compiler:

[ts]
Type 'Promise<Product[]>' is not assignable to type 'Promise<Product[]>'. Two different types with this name exist, but they are unrelated.
Types of property 'catch' are incompatible.
Type '(errorFunc: ErrorFunc<Product[]>) => Promise<Product[]>' is not assignable to type '(errorFunc: ErrorFunc) => Promise'.
Types of parameters 'errorFunc' and 'errorFunc' are incompatible.
Type 'void | U | Thenable' is not assignable to type 'Product[] | Thenable<Product[]>'.
Type 'void' is not assignable to type 'Product[] | Thenable<Product[]>'.
(method) GenericRestClient.performApiGet<Product[]>(apiPath: string, options?: ApiCallOptions): Promise<Product[]>

My code is really simple, what am I doing wrong?

import RX = require('reactxp')
import { GenericRestClient, ApiCallOptions }  from 'simplerestclients';
import SyncTasks = require('synctasks');

class MyRestClient extends GenericRestClient {
    constructor(private _appId: string) {
        super('https://myapi.com.br/api/v1/');
    }
    protected _getHeaders(options: ApiCallOptions): { [key: string]: string } {
        let headers = super._getHeaders(options);
        //headers['X-AppId'] = this._appId;
        return headers;
    }
    getAllProducts(): SyncTasks.Promise<Product[]> {
        return this.performApiGet<Product[]>('products');
    }
}

class Product {
    public Id: number;
    public Name: string;
    public PhotoURL: string;
    public Description: string;
    public Price: number;
    public QtyInStock: number;
    public Order: number;
    public CategoryId: number;
    public IsSelling: boolean;
    public NCM: string;
}

Thanks in advance

@rbravo - your code looks correct. Generally this error happens when you have a mismatch in dependency versions. Can you look at your app's package.json and ensure you're utilizing the latest versions of SyncTasks (0.2.23) and SimpleRestClients (0.1.0)

@berickson1 , thanks for your answer!
on my package.json I have:
"simplerestclients": "^0.1.0"
Looks correct, but although simplerestclients has a dependency on "synctasks": "^0.2.23" the version installed on my project was "synctasks": "^0.2.19", I don't know why!
now I updated it and it works just fine, thanks!