Skip to content

Parameter info for elements of destructured array in function parameter position are incorrect #4818

Description

@NoelAbrahams

Hi,

Version: VS 2015/TS 1.6.2

There are few issues with intellisense in the following snippet

const f = (foo: (bar: string[]) => void) => { };

f(a=> {

    const aa = a[0];
    aa.charAt(0); // Okay: inferred as string
});

f(([a, b]) => {

    a.charAt(0); // Not okay: inferred as `any`
});

Points to note:

  • Hovering over [a, b] in the very last function call shows the type of a to be any and the type of b to be string.
  • Furthermore, this is not constant. Adding b.charAt(0); to the function body, and then hovering over a, b shows a to be string and b to be any.
  • In either case, there is no completion for either a or b, when they are dotted off.

This is only a problem with quick info and completion. If I were to change the function to have a number array parameter

const f = (foo: (bar: number[]) => void) => { };

Then all charAt calls are underlined in red as expected and the file fails to compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDuplicateAn existing issue was already createdFixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions