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.

Removing "private" modifier from types

See original GitHub issue

[Feature suggestion] How about this (for Typescript 2.8+):

type Friend<T> = {
    -private [P in keyof T]: T[P]
}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:109
  • Comments:56 (4 by maintainers)

github_iconTop GitHub Comments

35reactions
NN---commented, Mar 19, 2020

Does this remove protected too ?😃

Perhaps there is also need for the opposite, adding public for all privates ?

+public [P in keyof T]: T[P];
30reactions
Lodincommented, May 7, 2018

I suppose it is very useful feature, because it allows to work better with decorators. For me it is quite common case when you create property decorator and need access to some private or protected property, but cannot get it due to current restrictions. That’s why you are forced to use any type in decorators, and it does not guarantee type-safety.

The minimal example of this kind of decorators is following:

type Public<T> = {
    +public [P in keyof T]: T[P]
}

const decorate = (target: any, properyName: string) => ({
  get(this: Public<Base>): any { // here instead of `Public<Base>` I use `any` for now
    return this.props[propertyName];
  }, 
  set(this: Public<Base>, value: any): void {
    this.props[propertyName] = value;
  },
});

class Base {
  private props: {[key: string]: any} = {};

  @decorate
  public property: string = '';
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

bypass / remove readonly modifier from private class properties
I want to override the readonly modifier on a class property. Unfortunately the properties are private and I can't use something like type...
Read more >
Controlling Access to Members of a Class - Oracle Help Center
The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can...
Read more >
Access Modifiers in Java - GeeksforGeeks
There are four types of access modifiers available in java: ... Private: The private access modifier is specified using the keyword private.
Read more >
Code Syntax Style: Modifiers | JetBrains Rider Documentation
C# modifiers of types and type members can be written in any order. ... By default, JetBrains Rider suggests to use private and...
Read more >
TypeScript Access Modifiers
The private modifier limits the visibility to the same-class only. When you add the private modifier to a property or method, you can...
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 Hashnode Post

No results found