Skip to content

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

Description

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.

Activity

  1. devanshj commented on Jun 22, 2021

    @devanshj
    Author

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

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions