Skip to content

Type 'Array<any>' is not assignable to type 'any[]'. Property '[Symbol.iterator]' is missing in type 'Array<any>' #8327

@natarajanmca11

Description

@natarajanmca11

In my typescript project, linq.ts throws the following error.

Soruce Code :

    export {};

    type Predicate<T> = (item: T) => boolean;

    declare global {
        interface Array<T> {
            First: {
                (): T;
                (Func: Predicate<T>): T;
            };
            Where(Func: Predicate<T>): Array<T>;
        }
    }

    Array.prototype.Where = function (func: (x: any) => boolean): Array<any> {
        let result: Array<any> = [];
        let a: Array<any> = this;
        for (let i of a) {
            if (func(i)) {
                result.push(i);
            }
        }
        return result;
    };

    Array.prototype.First = function (func?: (x: any) => boolean): any {
        let a: Array<any> = this;
        if (a.length === 0) {
            throw 'Array does not contain elements';
        }
        if (!func) {
            return a[0];
        }
        let result: Array<any> = a.Where(func);
        if (result.length === 0) {
            throw 'Array does not contain elements';
        }
        return result[0];
    };

Error :

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions