Typescript member accessability for members only used by the custom element?

When starting out with building Aurelia custom elements (using typescript) I decided to declare members only used by the custom element as private, even if they are also used in the html template. This makes them hidden if someone decides to make a view-model.ref on the element and access the custom element class through code, but since “private” doesn’t really exist in javascript, the html template can still access them.

Now my IDE of choice, Visual Studio 2017, has gotten more clever with typescript classes and started doing this for these private members as they are only read in the html template;
image

So my instinct is to now remove private on these members so that the IDE wont confuse myself and my colleagues. But then it will exposed if someone interacts with the element through code as described above, which could cause unexpected usage of the custom element.

What are your thoughts on this?

I used to mark them private as well. But then i changed all to public and decorated with @internal since it best describes the intention, at least for me. Also internal will make the typing disappear if you are building a library

1 Like

Interesting. Where can I read more about the @internal decorator? From where do I import it? (Google fails me…)

Oh its just a comment. You decorate the class member with multiline comment block and add @internal at the start of it

I see. It doesn’t seem to work in Visual Studio, I still get intellisense for that member.

I am somewhat familiar with JSDoc (http://usejsdoc.org/) but @internal is not listed there. What standard does @internal come from?

Yes, its only for communication, which means consumer of the class will be signaled that its not available for use outside of the class. Theoretically, they are not private, making them as such could cause confusion down the road

OK. Sorry, but I think I misunderstood this. How do you mean the “typing disappears”?

for:

class Abc {
  private d(): void {
  }
}

will generate .d.ts as:

class Abc {
  private d(): void;
}

for:

class Abc {
  /*@internal */
  d(): void {
  }
}

will generate .d.ts as:

class Abc {
  
}

So what I’ve been describing about my choice is to make things look like they way they actually are. With optional comment as a signal for reader of the class members. In stead of trying to make theoretically-public members private. The @internal comment servers 2 purposes: for app, it signals that the public member is a semi private member, shouldn’t be used directly outside of the class. For lib, it will be stripped from generated .d.ts, thus user of the lib will not see it, yielding similar effect to private.

Ok, got it. Thanks for your input. Using some comment like that seems like the way to go.

Considering that @internal then is some part of the spec of generation of *.d.ts files it shouldn’t be too far-fetched to suggest to IDEs that it should also affect intellisense.

(In my case I’m not building a lib, the custom elements are directly used within the same app/code base.)