Closed
Description
Bug Report
π Search Terms
generic function infer unknown type without specifying parameter type
π Version & Regression Information
Faced it with 4.3.5, but it still occurs in 4.6.3 and Nightly (v4.7.0-dev.20220302)
β― Playground Link
Playground link with relevant code
π» Code
interface Options<TParams, TDone, TMapped> {
fetch: (params: TParams, foo: number) => TDone,
map: (data: TDone) => TMapped
}
function example<TParams, TDone, TMapped>(options: Options<TParams, TDone, TMapped>) {
return (params: TParams) => {
const data = options.fetch(params, 123)
return options.map(data)
}
}
interface Params {
one: number
two: string
}
example({
// WORKS
fetch: (params: Params) => 123,
map: (number) => String(number)
})
example({
// WORKS
fetch: (params: Params, foo: number) => 123,
map: (number) => String(number)
})
example({
// INFERS "unknown"
fetch: (params: Params, foo) => 123,
map: (number) => String(number)
})
π Actual behavior
In 3rd example, without explicitly specifying foo
parameter type, the return type of fetch
function infers as unknown
.
FYI: foo
type infers correctly from Options
inferface.
π Expected behavior
The code 3rd example works like the first two examples, correctly infering the fetch
function's return type.