้•œๅƒ็ซ™็‚น ยท ๆœฌ้กต็”ฑ็ฌฌไธ‰ๆ–น GitHub ๅช่ฏป้•œๅƒๆไพ›๏ผŒ้ž GitHub ๅฎ˜ๆ–น็ซ™็‚น๏ผŒไธๆŽฅๅ—ไปปไฝ•็™ปๅฝ•ๆˆ–ๅ‡ญๆฎ่พ“ๅ…ฅใ€‚ๅ‰ๅพ€ github.com
Skip to content

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

Description

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

Activity

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

    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