Let's say I have a JavaScript class
/**
* @element my-element
*/
export class MyElement extends HTMLElement {
publicMethod() {}
/** @private */
privateMethod() {}
}
customElements.define('my-element', MyElement);
and a declaration file, generated using declaration
and allowJs
:
export class MyElement extends HTMLElement {
publicMethod(): void;
/** @private */
privateMethod(): void
}
I also, in a post-build script, concat this to the declaration file:
declare global { interface HTMLElementTagNameMap { 'my-element': MyElement; } }
When using this element in a typescript file, I get access to privateMethod
in autocomplete.
import 'my-element'
const me = document.createElement("my-element")
me.// autocompletes `privateMethod`
How can I instruct tsc
to mark as private any methods, fields, or properties that are annotated with the @private
JSDoc tag?
['privateMethod']
syntax, VS Code will autocomplete private methods – Labium