Skip to content

Different inferencing in function generic between normal function and arrow function.Β #53924

Closed
@ellemedit

Description

@ellemedit

Bug Report

πŸ”Ž Search Terms

typescript function generic inference, typescript inference arrow function

πŸ•— Version & Regression Information

5.0.4, nightly build are being reproduced

⏯ Playground Link

https://tsplay.dev/mp0YXm

πŸ’» Code

function test<T = unknown>(options: {
    a: (c: T) => void,
    b: () => T
}) {}

test({
    a: (c) => { c }, // c is number
    b: () => 123
})

test({
    b: () => 123,
    a: (c) => { return c }, // c is number
})

test({
    b() { return 123 },
    a(c) { return c }, // c is number
})

test({
    a(c) { return c }, // c is unknown, expected number as above inferences
    b() { return 123 }
})

πŸ™ Actual behavior

last 'a' parameter 'c' inner test() inferred as unknown

πŸ™‚ Expected behavior

last 'a' parameter 'c' inner test() inferred as number

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