Skip to content

Probable bug: Contextual inference and intellisense at call sites buggy in case of circular type parameter constraints like T extends M<T>Β #44821

Closed
@devanshj

Description

@devanshj

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

Playground

πŸ’» 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions