Skip to content

Incorrect automatically type infer #57921

Closed as not planned
Closed as not planned

Description

@hanakannzashi

🔎 Search Terms

automatically infer

🕗 Version & Regression Information

  • This is NOT a crash

⏯ Playground Link

No response

💻 Code

There is no issue

function test<T>(t1: T, t2: T): never {
  throw Error('todo');
}

function custom<T>(f: (data: T) => T): T {
  throw Error('todo');
}

async function main() {
  test(10, custom((data) => {
    throw Error('todo')
  }))
}
no-issue

Function custom correctly inffered

There is issue

function test<T>(options: {
  t1: T,
  t2: T
}): never {
  throw Error('todo');
}

function custom<T>(f: (data: T) => T): T {
  throw Error('todo');
}

async function main() {
  test({
    t1: 10,
    t2: custom((data) => {
      throw Error('todo')
    })
  })
}
issue

Function custom incorrectly inffered, the T should be number instead of unknown

🙁 Actual behavior

Function custom incorrectly infered, the T infered as unknown

🙂 Expected behavior

Function custom correctly infered, the T infered as number

Additional information about the issue

No response

Activity

  1. RyanCavanaugh commented on Mar 25, 2024

    @RyanCavanaugh
    Member
  2. added
    Duplicate
    on Mar 25, 2024
  3. typescript-bot commented on Mar 28, 2024

    @typescript-bot
    Contributor

    This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  4. locked as resolved and limited conversation to collaborators on Oct 22, 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

    Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions