Skip to content

generics can only detect arrow function in object but not function expression #57572

@Asweallcan

Description

@Asweallcan

🔎 Search Terms

typescript
generics
arrow function
function

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play?#code/C4TwDgpgBAwlC8UA8AoK6oFkLABYHsATAZwBo0MBBYYAQwGNcJCEoAKAWxwJIC4tuRYgEoEAPigA3fAEtCKMWwrp8YYDPwA7YvwDeyjOi54h-bCZIBuA4do0GTQv2p1Gza4YC+KUfAm1NEGsUSVoAJ1h8DjAtCE1gfjhENl8JXShvFBgomM044DZ9W3s3Qk5BElEiwwxjHmIAOgAjFpSoAHp2qDww-AB3buIoCDDesINPckM60yhqmqgWprb07y8UT2EULJzY+MKDO1dHcosROZtaisalts6ofABrCamrs71L9CX+Nr85jImG2EQA

💻 Code

type C = <
        Methods,
        Attached = (methods: Methods) => void
    >(
        options: {
            methods: Methods;
            attached: Attached;
        }
    ) => any;
    
    var Component: C = () => { }
    
    Component({
        attached(methods) {
            methods.bbb() // throw ts error
        },
        methods: {
            bbb() { }
        }
    })
    
    Component({
        attached(methods) {
            methods.bbb() // ok
        },
        methods: {
            bbb: () => { }
        }
    })

🙁 Actual behavior

Parameter "methods" in "attach" function should be functions declared in "methods" property, but it works only when function is arrow function.

🙂 Expected behavior

Parameter "methods" in "attach" function should be functions declared in "methods" property

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