Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Functional properties make inference non-working in case of circular type parameter constraints like T extends M<T> #44700

Closed
devanshj opened this issue Jun 22, 2021 · 1 comment

Comments

@devanshj
Copy link

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.

@devanshj
Copy link
Author

Oh shoot I realized it's same as #40439 ahaha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant