Skip to content

Not Assignable Types That Should Be #3672

Closed
@pixelshaded

Description

@pixelshaded

I'm using angular-resource.d.ts

Type 'IResourceArray<IResource<ICompany>>' is not assignable to type 'IGridFilterOption[]'.
interface IResourceArray<T> extends Array<T> {
    /** the promise of the original server interaction that created this collection. **/
    $promise : angular.IPromise<IResourceArray<T>>;
    $resolved : boolean;
}
// Instance calls always return the the promise of the request which retrieved the object
// https://github.com/angular/angular.js/blob/v1.2.0/src/ngResource/resource.js#L538-L546
interface IResource<T> {
    $get(): angular.IPromise<T>;
    $get(params?: Object, success?: Function, error?: Function): angular.IPromise<T>;
    $get(success: Function, error?: Function): angular.IPromise<T>;

    $query(): angular.IPromise<IResourceArray<T>>;
    $query(params?: Object, success?: Function, error?: Function): angular.IPromise<IResourceArray<T>>;
    $query(success: Function, error?: Function): angular.IPromise<IResourceArray<T>>;

    $save(): angular.IPromise<T>;
    $save(params?: Object, success?: Function, error?: Function): angular.IPromise<T>;
    $save(success: Function, error?: Function): angular.IPromise<T>;

    $remove(): angular.IPromise<T>;
    $remove(params?: Object, success?: Function, error?: Function): angular.IPromise<T>;
    $remove(success: Function, error?: Function): angular.IPromise<T>;

    $delete(): angular.IPromise<T>;
    $delete(params?: Object, success?: Function, error?: Function): angular.IPromise<T>;
    $delete(success: Function, error?: Function): angular.IPromise<T>;

    /** the promise of the original server interaction that created this instance. **/
    $promise : angular.IPromise<T>;
    $resolved : boolean;
}
interface ICompany {
   id: number;
   name: string;
}
interface IGridFilterOption {
    id: number;
    name: string;
}

And this code has the line generating the error.

let companyPromise: IPromise<void> = this.companyService.getAll()
    .then((companies: IResourceArray<IResource<ICompany>>) => {
        let filter: IGridFilter = _.find(this.companyGridMetadata.filters, (f: IGridFilter) => {
            return f.name === 'Company';
        });
        filter.options = companies;
});

I feel like filter.options = companies should be valid. ICompany and IGridFilterOption have the same properties. IResource is simply a wrapper around ICompany that adds CRUD ops to it. IResourceArray extends Array by adding promise related properties.

Types of property 'push' are incompatible.
    Type '(...items: IResource<ICompany>[]) => number' is not assignable to type '(...items: IGridFilterOption[]) => number'.
      Types of parameters 'items' and 'items' are incompatible.
        Type 'IResource<ICompany>' is not assignable to type 'IGridFilterOption'.
          Property 'id' is missing in type 'IResource<ICompany>'.

What needs to be changed in the type definitions to make this assignment valid?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions