Skip to content

Contextual typing of spread elements #2172

Closed

Description

The following gets contextually typed:

var x: ((p: string) => number)[] = [p => p.length];

But the following arguably should also be:

var x: ((p: string) => number)[] = [...[p => p.length]];

Same is true for calls:

function foo(...rest: ((p: string) => number)[]) {}
foo(p => p.length);

So we should do it for the following as well:

function foo(...rest: ((p: string) => number)[]) {}
foo(...[p => p.length]);

Activity

  1. added
    DeclinedThe issue was declined as something which matches the TypeScript vision
    and removed on May 4, 2015
  2. RyanCavanaugh commented on May 4, 2015

    @RyanCavanaugh
    Member

    Supported on the grounds of consistency, but at the same time there's no reason to spread a bare literal, so what's the point?

  3. JsonFreeman commented on May 4, 2015

    @JsonFreeman
    ContributorAuthor

    Yeah that makes sense.

  4. locked and limited conversation to collaborators on Jun 18, 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

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions