Closed as not planned
Closed as not planned
Description
π Search Terms
function parameter inference
π Version & Regression Information
- This changed between versions 3.7.5 and 3.8.3
β― Playground Link
π» Code
type Options<TContext> = {
onStart?: () => TContext
onEnd?: (context: TContext) => void
}
function create<TContext>(builder: (arg: boolean) => Options<TContext>) {
return builder(true)
}
// Works
create((arg: boolean) => ({
onStart: () => ({ time: new Date() }),
onEnd: (context) => console.log(context.time)
}))
// Works
create(() => ({
onStart: () => ({ time: new Date() }),
onEnd: (context) => console.log(context.time)
}))
// Fails!
create((arg) => ({
onStart: () => ({ time: new Date() }),
onEnd: (context) => console.log(context.time) // Error: 'context' is of type 'unknown'
}))
π Actual behavior
The value of TContext
is not inferred properly when an parameter is included in the builder function. Removing the argument resolves the issue, as does adding an explicit type for the argument.
π Expected behavior
The value of TContext
should be inferred properly, regardless of if a parameter is included in the builder function, or if the parameter has or does not have an explicit type.
Additional information about the issue
No response