Closed
Description
TypeScript Version: 3.7-beta
Search Terms:
Code
type RefSelf<Input extends Record<string, (...args: any[]) => unknown>> = {
[k in keyof Input]: () => ReturnType<Input[k]>
}
declare function calculate <
Input extends Record<string, (self: RefSelf<Input>) => unknown>,
>(input: Input): RefSelf<Input>
const { fourtyTwo, fourtyTwo2 } = calculate({
fourtyTwo: () => 42,
// (parameter) self: RefSelf<{fourtyTwo: unknown; fourtyTwo2: unknown;}>
// (property) fourtyTwo: () => any
fourtyTwo2: (self) => self.fourtyTwo(),
})
Expected behavior:
-
output of the calculate be inferred as
{ fourtyTwo: () => number, fourtyTwo2: () => number }
-
self
be inferred asRefSelf<{ fourtyTwo: unknown; fourtyTwo2: unknown; }>
Actual behavior:
-
output of the calculate be inferred as
{ fourtyTwo: () => number, fourtyTwo2: () => any }
-
self
be inferred asRefSelf<{ fourtyTwo: () => number; fourtyTwo2: () => number; }>
Related Issues: