Skip to content

Infering from recursive homomorphic mapped types #12606

Description

@mhegazy

ran into this writing a declaration for Ramda applySpec.

type Func<T> = (...args: any[]) => T;
type Spec<T> = {
    [P in keyof T]: Func<T[P]> | Spec<T[P]> ;
};

/**
 * Given a spec object recursively mapping properties to functions, creates a function 
 * producing an object of the same structure, by mapping each property to the result 
 * of calling its associated function with the supplied arguments.
 */
declare function applySpec<T>(obj: Spec<T>): (...args: any[]) => T;

var g1 = R.applySpec({
    sum: (a) => 3,
    nested: {
        mul: (b) => "n"
    }
});

// Expected:
// g1: {sum: number; nested: { mul: string; }};

// Actual:
// g1:  {sum: number; nested: { mul: (a)=>string; }};

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions