Skip to content

Inconsistent Treatment of Shorthand Functions #11062

Closed

Description

@ChrisGroh

TypeScript Version: 2.0.3

Code

// A *self-contained* demonstration of the problem follows...
function testFunction(x: string | Function): any {
    if (typeof x === 'string') {
        return {
            key: function (a: any, b: any) {
                // Fine, x is string
                return a[x];
            }
        };
        return {
            key(a: any, b: any) {
                // Fails, x is string | Function here
                return a[x];
            }
        };
    }
}

Expected behavior:
Compiles fine

Actual behavior:
Error: An index expression argument must be of type 'string', 'number', 'symbol', or 'any'.

Activity

  1. mhegazy commented on Sep 22, 2016

    @mhegazy
    Contributor

    duplicate of #10501

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

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions