Skip to content

Getting error 2576 when accessing static methods of a class as a passed parameter. #62815

@TyIsI

Description

@TyIsI

🔎 Search Terms

Related: #2576

2576 accessing static method from passed parameter variable -union

🕗 Version & Regression Information

This is the behavior in every version I tried through the playground, including the nightly, and I reviewed the FAQ for entries about static member access errors

⏯ Playground Link

Playground Link

💻 Code

class FafoTest1 {
    name: string
    fafo: Fafo1

    constructor(name: string, fafo: Fafo1) {
        this.name = name
        this.fafo = fafo
    }

    test(): void {
        console.log('testing test')

        // Property 'test' does not exist on type 'Fafo1'. Did you mean to access the static member 'Fafo1.test' instead?(2576)
        this.fafo.test()
    }
}

class Fafo1 {
    static get FafoTest1(): (name: string) => FafoTest1 {
        return (name: string): FafoTest1 => {
            const newInstance = new FafoTest1(name, Fafo1)

            return newInstance
        }
    }

    static test(): void {
        console.log('test')
    }
}

🙁 Actual behavior

I received the following error:

Property 'test' does not exist on type 'Fafo1'. Did you mean to access the static member 'Fafo1.test' instead?(2576)

🙂 Expected behavior

I was not expecting an error, as the local field type is exactly the same.

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions