Click here to Skip to main content
16,022,060 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a JS class. In the class is a private method called #setRequired. But calling causes this syntax error: Private field '#setRequired' must be declared in an enclosing class.

Note. I know that private instance members can only be called inside a class prefixed with 'this.#<member_name>' notation and static members through <class_name>.#<member_name> notation.

I have a other classes that also have private members but they run without problem. Only this one particular class.

What I have tried:

What have I tried is finding the internet what causes this problem since this is the first time I encountered this.
Posted
Comments
OriginalGriff 10-Sep-24 1:28am    
With no idea what your code actually looks like, we can't help you.
Cut down your code to the bare minimum that shows the error, and add that fragment to your question using the "Improve question" link.

Either the act of cutting it down will show you what the problem is, or it will give us something solid to work with!
raddevus 10-Sep-24 14:09pm    
See if this helps...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties

1 solution

My guess here would be that you have another copy of #setRequired in your codebase that isn't inside a class.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900