Using `typeof this.#privateField` in declaration emit
See original GitHub issueclass StringHolder {
#data = "hello";
public getData(): typeof this.#data {
return this.#data;
}
}
error TS4055: Return type of public method from exported class has or is using private name 'this'.
8 public getData(): typeof this.#data {
~~~~
Seems strange that we even have this feature if we can’t use this in declaration emit.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Why can I access TypeScript private members when I shouldn ...
Private fields starts with # character ... My fix is to group private declarations together inside another class that is then instantiated in...
Read more >typeof - JavaScript - MDN Web Docs - Mozilla
The typeof operator returns a string indicating the type of the operand's value.
Read more >How to: Define a Generic Type with Reflection Emit - .NET ...
See how to define a generic type with reflection emit. ... In this example, the type of the field is specified by type...
Read more >Private Methods and Properties in TypeScript Classes
We can prefix the constructor parameters with the public or private keyword to automatically have TypeScript assign the parameter as a property ...
Read more >Documentation - Classes - TypeScript
As with other JavaScript language features, TypeScript adds type annotations and ... A field declaration creates a public writeable property on a class:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Why is it complaining about
this
rather than the actual thing that’s private?I’m seeing the same error even for simple cases like this:
It’s convenient to return
typeof this
in this case because it will also have the right type for the subclasses ofX
.