question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Protected and private functions are not visible when 'this' context "arg" is provided if it doesn't explicitly define a return type

See original GitHub issue

Bug Report

🔎 Search Terms

private type is not visible

🕗 Version & Regression Information

  • This is the behavior in every version I tried (3.3.3 -> Nightly), and I reviewed the FAQ for entries about types and not-a-bugs.

⏯ Playground Link

Playground link with relevant code

💻 Code

interface Interface1 {}
interface Interface2 {}

class Mixin {
    private field: any;
    protected field2: any;

    protected doOneThing() {}
    protected doOneThingVoid(): void {}

    private doTwoThings() {}
    private doTwoThingsVoid(): void {}

    public doThreeThings() {}
    public doThreeThingsVoid(): void {}

    doThing(this: Mixin & (Interface1 | Interface2)) {
        // Not fine
        this.field2;
        this.doOneThing();
        this.doOneThingVoid();
        this.doTwoThings();
        // Fine
        this.field;
        this.doTwoThingsVoid();
        this.doThreeThings();
        this.doThreeThingsVoid();
    }
}

🙁 Actual behavior

The protected fields and functions are declared as not visible. The private functions that implicitly return void are not visible.

🙂 Expected behavior

Protected fields are visible. Functions that return an implicit void are visible and therefore treated the same as functions that return an explicit void.

Further Notes

It doesn’t matter if I return void, any return value will do. I’m also finding it odd that private works, but protected doesn’t even though protected should have greater visibility here. However it may be trying to say that it doesn’t think that we’re inside of a Mixin class instance, in which case neither private nor protected should be visible in that case, even though that’s not my preferred outcome. At minimum there shouldn’t be a difference between implicit and explicit void.

Yes this is used as a mixin with the ts-mixer library, however, the type errors are all contained within the class itself like the example above, and so are a problem without involvement of any mixin libraries.

Also this seems related to #29132 except there’s no generics used here. I also found #10637 when researching this, but that involves inheritance which isn’t in play here.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanCavanaughcommented, Aug 11, 2022

👀👀👀👀👀👀👀👀👀👀

1reaction
fatcerberuscommented, Aug 11, 2022

@DanielRosenwasser Not so; the only thing that seems to change is that this.doTwoThings(); is not an error anymore in your playground. Definitely weird in any case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

function with deduced return type cannot be used before it ...
My understanding is that both function-body and default argument are complete-class contexts in which the class and its member definitions, ...
Read more >
Access Control — The Swift Programming Language ...
A public variable can't be defined as having an internal, file-private, or private type, because the type might not be available everywhere that...
Read more >
Access Modifiers In Java - Tutorial With Examples
Note that the private entities are not even visible to the subclasses of the class. A private access modifier ensures encapsulation in Java....
Read more >
Visibility - Manual
Method Visibility ¶ ... Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined...
Read more >
Nullable reference types
A reference isn't supposed to be null. The default state of a nonnullable reference variable is not-null. The compiler enforces rules that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found