Skip to content

Smart structural generic type inference support #23733

Closed

Description

@pmunin

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>);
}

Activity

  1. AlCalzone commented on Apr 27, 2018

    @AlCalzone
    Contributor

    Is this #23696 possibly what you want?

  2. mhegazy commented on Apr 27, 2018

    @mhegazy
    Contributor

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

  3. typescript-bot commented on May 14, 2018

    @typescript-bot
    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 Jul 31, 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