-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
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
- In the return type annotation of
transform(), the instantiation expression (added by Instantiation expressions #47607)typeof func<A[K], K>reverts to it's generic constraint type ofF(<V extends A[number], K extends keyof A>(value: V, index: K, array: A) => any) when it is invoked. This causes the return type oftransform()to be a tuple ofanyinstead of{ type: A[K] }. - Using
ReturnType<F>in place of a instantiation expression from above example results in unresolved generics leaking from the function type
🙂 Expected behavior
- The instantiation expression
typeof func<A[K], K>intransform()should resolve to{ type: A[K] }. resshould 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created