Skip to content

Suggestion: Class friendships #2136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
markvandenbrink opened this issue Feb 25, 2015 · 2 comments
Closed

Suggestion: Class friendships #2136

markvandenbrink opened this issue Feb 25, 2015 · 2 comments
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Revisit An issue worth coming back to Suggestion An idea for TypeScript

Comments

@markvandenbrink
Copy link

Are there any plans to incorporate the friend keyword in TypeScript to allow class friendships and improve class encapsulation? I know (real) mixins and abstract classes are on the roadmap for 2.0. But friend classes would be practical as well...

A friend class should have access to the private and protected members of the class in which it is declared as a friend. For example:

class A friend B {
    private Message: string = "hello";
}

class B {
    private Message: string = "there";

    public Greeter(a: A): string {
        return a.Message + " " + this.Message;
    }
}
@danquirk
Copy link
Member

We haven't heard many other requests for this. We only recently added protected and there've been a fair number of asks for something like C#'s internal both of which are a lot more common in usage than friend. I wouldn't say we're likely to add this, certainly not in the near term unless there're some very compelling use cases that mesh with existing popular libraries.

@danquirk danquirk added the Suggestion An idea for TypeScript label Feb 25, 2015
@mhegazy mhegazy added the Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. label Dec 9, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Feb 22, 2016

marking as revisit. as @danquirk mentioned, #5228 is a better alternative here.

@mhegazy mhegazy closed this as completed Feb 22, 2016
@mhegazy mhegazy added the Revisit An issue worth coming back to label Feb 22, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Revisit An issue worth coming back to Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants