Typescript - utilizing objects as private or protected members

Is there a way to declare an object as protected or private in Typescript?

I have found that I cannot achieve this in an interface (only public is allowed), and attempts to do so inside the class does not work either.

private options : interface{
    collapsible  : boolean;
    collapsed    : boolean;
    editable     : boolean;
}

Any suggestions or hints would be greatly appreciated. Thank you.

Zoltán Tamási - Thanks for the help!

In the Interface

declare module ICoreModule{
    // protected or private
    interface IOptions{
        initWhenDataReady   : boolean;
        collapsible         : boolean;
        collapsed           : boolean;
        editable            : boolean;
    }

    export interface ICoreScope extends ng.IScope{
        sandboxSave : Function;
        data        : Object;
    }

    export interface Class extends App.Directive{
        $scope   : ICoreScope;
        $element : ng.IRootElementService;
        $attr    : ICoreAttr;
        $ctrl    : ng.IFormController;
    }
}

In the class:

protected options : ICoreModule.IOptions = <ICoreModule.IOptions>{
    initWhenDataReady   : true,
    collapsible         : true,
    collapsed           : true,
    editable            : true
};

Answer №1

When creating a class or interface within a module, you have the option to decide whether it should be exported by using the export keyword.

If a class or interface is not exported, it will only be accessible within the module in which it is declared.

However, if an unexported class or interface is referenced in any public member or method of an exported class, a compilation error will occur and it must be exported in order to resolve the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A subtle X icon tucked away in the corner of the homepage, a result of the jquery modal window

Struggling with an issue on a client's website - there are multiple jquery sections with buttons that open modal windows. The problem is that the close button for these modals appears on page load and is situated at the top right of the homepage. Is t ...

What mechanism allows a browser to detect changes in an element without using a setter method, simply through assignment with '=' symbol?

Can anyone explain how the browser is able to refresh the input element (or any other element) when I assign a value without using a setter method, but just through normal assignment: <script type="text/javascript> document.getElementById("element ...

Is there a way to develop a search script that can efficiently sift through the object using the provided script or a similar one?

$(document).ready(function(){ $.ajax({ dataType: 'jsonp', //data in jsonp contentType: "application/json; charset=utf-8", url: 'http://live.nhle.com/GameData/RegularSeasonScoreboardv3.jsonp', ...

Utilizing Javascript Conditional for Substitution

Currently, I have a JavaScript function that replaces all links with registration messages: <script> function replaceLinks() { var links = document.querySelectorAll('.restore a:link'); for (var i = 0; i < links.length; i++) { ...

Malfunctioning Bootstrap collapse feature

I am experiencing an issue with my modal that contains 2 blocks. When I click on the .emailInbound checkbox, it opens the .in-serv-container, but when I click on the .accordion-heading to reveal the comment section, the .in-serv-container collapses. What c ...

Why am I getting the error message "fromArray is not a function" in Three.js, Threex, and Javascript?

I've been putting in a lot of effort to figure this out on my own, but I'm completely new to three.js and javascript, and I really need some assistance. My goal is to import a model from threex into my three.js scene. However, when I try to add ...

Problems with the functionality of Javascript and ajax

I've created this JavaScript/AJAX code, but unfortunately, it's not functioning as expected and I am unable to determine the reason behind it. $(document).ready( function(){ $('#btn4').click( function(){ var plano = $(&a ...

Utilizing ngRepeat to build intricate rows within a table

I have a unique collection that appears as follows: { "10": {}, "12": { "20": { "value": 1, "id": 1, }, "100": { "value": 12, "id": 1, } }, "14": { "10 ...

The mystery of 'this' being null in Angular 2 service base class inheritance

I'm trying to create a universal error handler for my services using inheritance, but I'm facing an issue where 'this' is always null in the error handler. I can access the error handler, but I keep getting the following error: EXCEP ...

What are the differences between three.js domElement and the documentElement?

When referring to the THREE JS documentation, it suggests using domElement in this manner: document.body.appendChild(renderer.domElement); I'm wondering if there is a distinction between this approach and utilizing documentElement instead. This is c ...

Efficiently manage large datasets with Vue.js using the expand/collapse list AJAX pattern

Within my vuejs application, there is a page where I aim to showcase a list of clients. When a user expands an individual client row, it should reveal a list of proposals specific to that client. Additionally, there is an expand/collapse functionality for ...

Leverage the power of JavaScript's Map and Filter functions to manipulate

I have an array with the following elements: arr = ['AD', 'CI', 'AI'] Additionally, I have an object as shown below: { "AD": "Mailing Address", "CI": "Additional Interest", "HO": "Homeowners", "AI": "Additional Int ...

What could be causing the HTML layout to break at 769 pixels?

My current project involves creating a simple web page template using HTML/CSS. I followed a tutorial to implement the navigation code. However, at 769px, the layout breaks, causing the page to not be full width and hidden. Here is what happens: Here&ap ...

Is there a straightforward way to upload a folder in a ReactJS application?

I am searching for a way to upload a folder in ReactJS. I have a folder with .doc and .docx files in it, and I want the user to be able to upload the entire folder when they click the browse button. I need to prevent the user from selecting individual fi ...

It is not possible for the root segment to contain matrix parameters in Ionic 4

Has anyone figured out how to resolve this issue? .ts this.router.navigate(["", { clientId: data.id }]) Error message { path: "", component: HomePage, }, An unhandled error occurred: Root segme ...

Hey there! Can someone help me with an issue I'm having regarding authentication with spring-security and

Having an issue with my spring security + angular application. Upon clicking the authentication button, even when inputting correct data, I'm seeing this error in the console: Access to XMLHttpRequest at 'http://localhost:8080/api/v1/basicaut ...

Tips for displaying neatly formatted raw HTML code within an editable DIV element:

I am encountering an issue while attempting to display raw HTML within an editable DIV, as the <div> element is being turned into a comment. Here is the HTML I want to display (including the ``) : \`<div class="flexContainer">HE ...

Having trouble transferring information from a React frontend to an Express backend server

Attempting to transmit data from a React application to an Express server. React snippet: const imageRenderer = async () => { const res = await axios({ method: "post", url: "http://localhost:8080/previewRender", data: ...

Bridging the gap between the user interface and server

I'm developing a React Native app that requires user registration and authentication. I've successfully implemented a POST request to communicate with a mongoose server and store data in MongoDB. At this point, my goal is to enable users to input ...

Creating a map with just a Button Click in React

I'm currently working on a weather app and making good progress. Now, I'm looking to display additional information when a button is clicked. I have a 5-day forecast and want to show the details for each day. I've managed to filter the data ...