Closed
Description
Bug Report
π Search Terms
Circular type parameter constraint, intellisense, call site inference, contextual inference
Related - #44428 #40439
π Version & Regression Information
Tested with TS 4.3.4
β― Playground Link
π» Code
declare const m: <T extends M<T>>(m: T) => T
type M<Self, K = Exclude<keyof Self, "k" | "w">> =
{ a?: number
, b?: number
, c?: number
, d?: number
, k?: { $: K }
, w?: { $: "a" }
}
declare const $1: <T>(t: T) => { $: T }
declare const $2: <R>(t: R extends { $: infer X } ? X : never) => R
declare const $3: <R, T extends (R extends { $: infer X } ? X : never)>(t: T) => R
m({
a: 1,
b: 2,
k: $1("a"), // compiles: yes, completions: no
w: $1("a") // compiles: yes, completions: no
})
m({
a: 1,
b: 2,
k: $2("a"), // compiles: no, completions: yes
w: $2("a") // compiles: yes, completions: yes
})
m({
a: 1,
b: 2,
k: $3("a"), // compiles: no, completions: yes
w: $3("a") // compiles: yes, completions: yes
})
π Actual behavior
See code comments
π Expected behavior
All three cases or at least $2
and $3
should compile and user should be able to see completions "a" and "b" for the first parameter of $*
functions
It seems to be bug to me especially because in case of k
for $2
and $3
, you do get the completions and even the tooltip shows correct type parameters, but somehow the return type isn't the one thats expected and it doesn't compile AND it works totally fine with w
.