Skip to content

Type argument inference doesn't seem to work correctly with generic type aliases #5417

@seanchas116

Description

@seanchas116

Hi, I found that the following example that uses type argument inference and generic type alias doesn't compile:

Example with generic type alias (does not work)

type Maybe<T> = T | void;

function get<T>(x: Maybe<T>): T {
    return null; // just an example
}

let foo: Maybe<string>;
get(foo).toUpperCase(); // I think T == string in this function call...

Error

test.ts(8,10): error TS2339: Property 'toUpperCase' does not exist on type 'string | void'.

Example with generic interface (works)

interface Maybe<T> {}

function get<T>(x: Maybe<T>): T {
    return null;
}

let foo: Maybe<string>;
get(foo).toUpperCase();

Version

1.8.0-dev.20151027

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions