Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type inference with multiple type parameters #7491

Closed
biqas opened this issue Mar 12, 2016 · 2 comments
Closed

Type inference with multiple type parameters #7491

biqas opened this issue Mar 12, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@biqas
Copy link

biqas commented Mar 12, 2016

TypeScript Version:

1.9.0-dev / nightly (1.9.0-dev.20160311)

Code

class ModelA<T extends BaseData>
{
    public prop : T;

    public constructor($prop : T) { }

    public Foo<TData, TModel>(
        $fn1 : ($x : T) => TData,
        $fn2 : ($x : TData) => TModel) { }

    public Foo1<TData, TModel extends ModelA<any>>(
        $fn1 : ($x : T) => TData,
        $fn2 : ($x : TData) => TModel) { }

    public Foo2<TData extends BaseData, TModel extends ModelA<TData>>(
        $fn1 : ($x : T) => TData,
        $fn2 : ($x : TData) => TModel) { }
}

class ModelB extends ModelA<Data> { }

class BaseData
{
    public a : string;
}

class Data extends BaseData
{
    public b : Data;
}

class P
{
    public static Run()
    {
        var modelA = new ModelA<Data>(new Data());

        modelA.Foo(x1 => x1.b, x2 => new ModelB(x2));

        modelA.Foo1(x1 => x1.b, x2 => new ModelB(x2));

        // Why is this not working??? inferred type for x2 : BaseData
        modelA.Foo2(x1 => x1.b, x2 => new ModelB(x2)); // Error
    }
}

Expected behavior:
modelA.Foo2 call should infer the type.

Actual behavior:
Is not inferring the actual type.

@biqas biqas changed the title Type inference with multiple Type inference with multiple type parameters Mar 12, 2016
@vsiao
Copy link

vsiao commented Mar 13, 2016

looks like #7234

@mhegazy mhegazy added the Duplicate An existing issue was already created label Mar 29, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Mar 29, 2016

indeed a duplicate of #7234

@mhegazy mhegazy closed this as completed Mar 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants