Bug Report
π Search Terms
Circular type parameter constraint, inference change due to presence of functional property
Related: #40439
π Version & Regression Information
Tested with v4.3.4
β― Playground Link
Playground
π» Code
declare const m: <T extends M<T>>(m: T) => T
type M<Self, V = Prop<Self, "v">> =
{ v: V
, t?: (v: V) => void
}
type Prop<T, K> = K extends keyof T ? T[K] : "error"
// expected : M<{ v: number, t?: (v: number) => void }>
// actual : M<unknown>
m({
v: 1,
t: k => {}
})
// expected : M<{ v: number }>
// actual : M<{ v: number }>
m({
v: 1
})
π Actual behavior
In first function call of m, the parameter is inferred as M<unknown> in other words the TypeScript couldn't infer anything.
π Expected behavior
In first function call of m, the parameter should be inferred as M<{ v: number, t?: (v: number) => void }>. Especially given that removal of t works as seen in the second function call. Presence of a functional property shouldn't make the inference completely non-working.
Bug Report
π Search Terms
Circular type parameter constraint, inference change due to presence of functional property
Related: #40439
π Version & Regression Information
Tested with v4.3.4
β― Playground Link
Playground
π» Code
π Actual behavior
In first function call of
m, the parameter is inferred asM<unknown>in other words the TypeScript couldn't infer anything.π Expected behavior
In first function call of
m, the parameter should be inferred asM<{ v: number, t?: (v: number) => void }>. Especially given that removal oftworks as seen in the second function call. Presence of a functional property shouldn't make the inference completely non-working.