Skip to content

Quick info shows method with type any[] at declaration and string[] at use #16643

Closed

Description

TypeScript Version: nightly (2.5.0-dev.20170619)

Code

/// <reference path='fourslash.ts'/>

// @noImplicitAny: true

////interface I { m(): string[] }
////
////const i: I = {
////    /*1*/m() { return []; }
////}
////
////i./*2*/m();

verify.quickInfoAt("2", "(method) I.m(): string[]");
verify.quickInfoAt("1", "(method) m(): string[]");

Expected behavior:

Test passes.

Actual behavior:

AssertionError: At 1: quick info text: expected '(method) m(): any[]' to equal '(method) m(): string[]'

Activity

  1. DanielRosenwasser commented on Jun 20, 2017

    @DanielRosenwasser
    Member

    Here's what's happening here:

    1. The object is contextually typed by I
    2. The method m is contextually typed by the type of the property m within I
    3. The return expressions of m are contextually typed by the return type of the m within I
    4. The array literal is contextually typed, but arrays only change their type when contextually typed by a tuple type. You end up with a regular array whose element type is the widening undefined type.
  2. JsonFreeman commented on Jun 21, 2017

    @JsonFreeman
    Contributor

    Would it be reasonable for an empty array literal with a contextual type to just acquire the element type as its own? Even if the contextual type isn't a tuple

    That said, I think the current behavior is reasonable. After all, the method does return an empty array.

  3. mhegazy commented on Aug 17, 2017

    @mhegazy
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  4. 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

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions