-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api-extractor] Treat all underscore-prefixed variables as @internal
#2133
Comments
cc @Feiyang1 |
@internal
@internal
Could you provide an example source file showing how this would be useful? |
In the codebases I interact with, we generally prefix the private implementation details of public classes with underscores. This is meant to convey to developers that they should not rely on these members. This convention seems to now be enforced in API Extractor as well (#1170), but we still have to add A code sample would be: https:/firebase/firebase-js-sdk/blob/master/packages/firestore/src/api/geo_point.ts#L32 |
The Rush Stack lint rules follow the same convention, where
API Extractor extends the language's visibility concepts. The export class GeoPoint {
// Prefix with underscore to signal this is a private variable in JS and
// prevent it showing up for autocompletion when typing latitude or longitude.
private _lat: number;
private _long: number; Your example here is |
It sounds like your intended case is more like this: /**
* Renders a UI element.
* @public
*/
export class Widget {
/** Draw the thing */
public render(): void;
/** Return the internal implementation details */
public _getImplementation(): IWidgetInternal;
} Today API Extractor expects you to explicitly add an /**
* Renders a UI element.
* @public
*/
export class Widget {
/** Draw the thing */
public render(): void;
/**
* Return the internal implementation details
* @internal
*/
public _getImplementation(): IWidgetInternal;
} It would save some coding effort to automatically interpret any underscore-prefixed member as a Another idea would be to consider issuing a warning when |
Sorry, that was indeed a bad example. We are also using "_" prefixes for APIs that are only public because we need to access them from a different module, which essentially works around the fact that TypeScript doesn't have package-group (e.g As for "accidental underscores": We rely on our users to not use underscore-prefixed variables. Since we require this understanding from our users, I hope that I can also require this from my team and our contributors. I do think that this should be optional behavior though, as it will likely surprise (and break) some users |
Maybe it is better to make private members be treated as |
Is this a feature or a bug?
Please describe the actual behavior.
Would it be possible to add a setting that automatically treat all underscore-prefixed class members as
@internal
? If so, we are willing to contribute a PR but I would like to check first.This would be similar to #1170
The text was updated successfully, but these errors were encountered: