Skip to content

Cannot use "map" on a type of Array<T> | QueryList<T> because of signature mismatches #39602

@lazarljubenovic

Description

@lazarljubenovic

🐞 bug report

Affected Package

The issue is caused by package @angular/core.

Is this a regression?

No.

Description

I have a function that I wish to work with both QueryList and Array. Both types have the map method, but their types are not inter-compatible:

Error:(7, 12) TS2349: This expression is not callable.
  Each member of the union type '(<U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]) | (<U>(fn: (item: any, index: number, array: any[]) => U) => U[])' has signatures, but none of those signatures are compatible with each other.

🔬 Minimal Reproduction

Trivial to try out and quickly reproduce in any project you have open by writing this:
import { QueryList } from '@angular/core'
function test (x: Array<any> | QueryList<any>) {
  return x.map(x => x)
}

🌍 Your Environment

Angular Version:




     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 10.0.5
Node: 14.3.0
OS: linux x64

Angular: 10.0.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.5
@angular-devkit/build-angular     0.1000.5
@angular-devkit/build-optimizer   0.1000.5
@angular-devkit/build-webpack     0.1000.5
@angular-devkit/core              10.0.5
@angular-devkit/schematics        10.0.5
@angular/cli                      10.0.5
@ngtools/webpack                  10.0.5
@schematics/angular               10.0.5
@schematics/update                0.1000.5
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0

Anything else relevant? No.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: coreIssues related to the framework runtimecore: queriescross-cutting: typesfeatureLabel used to distinguish feature request from other issuesfeature: under considerationFeature request for which voting has completed and the request is now under consideration

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions