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

Smart structural generic type inference support #23733

Closed
pmunin opened this issue Apr 27, 2018 · 3 comments
Closed

Smart structural generic type inference support #23733

pmunin opened this issue Apr 27, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@pmunin
Copy link

pmunin commented Apr 27, 2018

TypeScript Version: 2.8.1

Problem: when there are too many generic parameters (e.g. nested generic interfaces), it gets hard to remember the order of those parameters. Some smart structural generic type inference needed.

Code

type ComplexGeneric1<TArg1, TArg2>={
    arg1:TArg1,
    arg2:TArg2,
}
type ComplexGeneric2<TArg1, TArg2>={
    arg1:TArg1,
    arg2:TArg2,
}

interface IMyInterface<TArg11=number,TArg12=number, TArg21=number, TArg22=number>
{
    myFunc(p1:ComplexGeneric1<TArg11, TArg12>, p2:ComplexGeneric2<TArg21, TArg22>);
}

var actualImplementation:IMyInterface<number,string,number, string>={
    myFunc(p1,p2)
    {
        //
    }
}

There should be a way to declare IMyInterface generic to be able to create implementation the following way:

var desiredImplementation:IMyInterface<{ 
        p1:{arg1:number, arg2:string},
        p2:{arg1:number, arg2:string}
    }>=
{
    myFunc(p1,p2)
    {
        //p1.arg1 = 123
        //p1.arg2 = "hello world"
    }
}

Is there a way to define IMyInterface to make it happen? Am I the only one who would like to have it?

I would expect something like this to work, but it doesn't:

interface IMyInterface<TStructure extends ({p1: {arg1:TArg11, arg2:TArg12},p2:{arg1:TArg21, arg2:TArg22}}), TArg11=number,TArg12=number, TArg21=number, TArg22=number>
{
    myFunc(p1:ComplexGeneric1<TArg11, TArg12>, p2:ComplexGeneric2<TArg21, TArg22>);
}
@AlCalzone
Copy link
Contributor

Is this #23696 possibly what you want?

@mhegazy
Copy link
Contributor

mhegazy commented Apr 27, 2018

indeed a duplicate of #22631 and should be fixed by #23696

@mhegazy mhegazy added the Duplicate An existing issue was already created label Apr 27, 2018
@typescript-bot
Copy link
Collaborator

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

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 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

4 participants