Skip to content

Array.concat() 's params wrong!!! #17447

Closed

Description

@scp1513

TypeScript Version: 2.4.1

Code

let a: ReadonlyArray<number> = [];
let b: number[] = [];
// compile error
let c = b.concat(a);
// you see Array.concat() doesn't change the params

Expected behavior:

Actual behavior:

Activity

  1. MrKou47 commented on Jul 27, 2017

    @MrKou47
    let a: ReadonlyArray<number> = [];
    let b: number[] = [];
    let c = b.concat([...a]);

    this will be ok.

  2. scp1513 commented on Jul 27, 2017

    @scp1513
    Author

    Bo Kou (@MrKou47) It works. thanks.

  3. added
    Bug
    Domain: lib.d.ts
    on Jul 27, 2017
  4. arusakov commented on Sep 13, 2017

    @arusakov
    Contributor

    Ryan Cavanaugh (@RyanCavanaugh)
    Code example generates error (TypeScript 2.5.2):

    [ts]
    Argument of type 'ReadonlyArray<number>' is not assignable to parameter of type 'number | number[]'.
      Type 'ReadonlyArray<number>' is not assignable to type 'number[]'.
        Property 'push' is missing in type 'ReadonlyArray<number>'.
    

    Is it right definition for push method for ReadonlyArray<T>?

    push(): never
    

    Also we need the same definitions for other methods, like pop and so on... Am I right?

  5. added this to the milestone on Sep 14, 2017
  6. mhegazy commented on Sep 14, 2017

    @mhegazy
    Contributor

    PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

  7. NaridaL commented on Sep 18, 2017

    @NaridaL
    Contributor

    This is a duplicate of #17076 and has been fixed by #17806.

  8. added
    Duplicate
    and removed
    Bug
    Domain: lib.d.ts
    on Sep 18, 2017
  9. modified the milestone: on Sep 18, 2017
  10. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions