Skip to content

Explicit spesifiying generic type parameters, while remain should be infer from function parameters #25603

Closed

Description

Expect that the remaining generic type parameters that are not explicitly set, should be inferred from the function parameters.

const testsCallBack = {
	test : function (callback : (err : any, result : string) => void)
}

function Prom<R extends any, M extends keyof O = any, O extends {} = any>(object : O, method : M) : void

const sftpWrapper = Prom<ssh2.SFTPWrapper>(testsCallBack, 'test'); // I would expect that the typing engine should infer the remain generics that are not explicitly set.

const sftpWrapper = Prom<ssh2.SFTPWrapper>(testsCallBack, 'tet');// Compiler Error
const sftpWrapper = Prom(ssh2, 'fastGet');// returns a good implementation of the types library

Also see post regarding top type unknown, which could also fix this problem, basically comes down to this being a type infer issues/bug in my opion.

#24439

Activity

  1. AlCalzone commented on Jul 12, 2018

    @AlCalzone
    Contributor

    I think you're looking for #23696

  2. wesleyolis commented on Jul 12, 2018

    @wesleyolis
    Author

    Their is alot in that post,
    AlCalzone Their is alot in that post, but basically the typing engine inferring an empty {} for the function call below, cause these to function to also be identical, were the more stricter one is chosen over the less stricter one based on parameters.

    Typically I envisage this to be order thing, were one would typically choose the least constraining function call when the type system was to intersect the function type signature.
    This is typically not what we want when we wanting to return different return type signature based on input signature, we wan the return type signature to be choose from the function call signature, that has the stricts constrains that match.

    What are you thoughts regarding, this belongs with the other post, it fit with the partial infer type from air of that post.

    const testsCallBack = {
    	test : function (callback : (err : any, result : string) => void)
    }
    
    function Prom<R>(object : {}, method : string) : () => Bluebird<R>
    function Prom<O extends {}>(object : O, method : keyof O) : Bluebird<Extract<O>>
    
    const sftpWrapper = Prom(testsCallBack, 'test'); // return type BlueBird<{}>
  3. wesleyolis commented on Jul 12, 2018

    @wesleyolis
    Author

    Looks like I will have to check the next release versions, to see if it is all resolved..
    I think the part of concern would be the return type and finding the most restrictive match to return the return type to use.

  4. typescript-bot commented on Jul 25, 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.

  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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