Skip to content

Incorrect automatically type inferΒ #57921

Closed as not planned
Closed as not planned
@hanakannzashi

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

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