Skip to content

Higher Order Instantiation Expressions don't resolve types correctly #52035

Closed
@Thundercraft5

Description

@Thundercraft5

Bug Report

🔎 Search Terms

  • higher order instantiation expression
  • instantiation expressions
  • instantiation expression loses generic
  • nested instantiation expression doesn't resolve
  • nested instantiation expression

🕗 Version & Regression Information

TS 4.7+ (in every version I tried, it seems to be there from start this feature was added).

⏯ Playground Link

Playground link with relevant code

💻 Code

declare function transform<
    const A extends readonly any[], 
    F extends <
        V extends A[number], 
        K extends keyof A,
    >(value: V, index: K, array: A) => any
>(array: [...A], func: F): { 
    [K in keyof A]: ReturnType<typeof func<A[K], K>> 
};

const $2 = transform(["object", "string", "number"], k => ({ type: k }));
    // ^?
    // Should be [{ type: "object" }, { type: "string" }, { type: "number" }], but is [any, any, any]

🙁 Actual behavior

🙂 Expected behavior

  • The instantiation expression typeof func<A[K], K> in transform() should resolve to { type: A[K] }.
  • res should resolve to [{ type: "object" }, { type: "string" }, { type: "number" }].
  • Functions used in higher order instantiation expressions should resolve correctly and not revert to their constraint types.

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