Skip to content
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

Mark publicly-visible internal properties as @internal #5768

Closed
cartant opened this issue Sep 29, 2020 · 7 comments
Closed

Mark publicly-visible internal properties as @internal #5768

cartant opened this issue Sep 29, 2020 · 7 comments
Labels
TS Issues and PRs related purely to TypeScript issues

Comments

@cartant
Copy link
Collaborator

cartant commented Sep 29, 2020

We should mark all publicly-visible properties - e.g. there are a whole bunch in Subject - as @internal - in the JSDoc - so that it's clear they should not be used.

Note that we cannot use TypeScript's stripInternal compiler option:

Strip Internal - stripInternal

Do not emit declarations for code that has an @internal annotation in it’s JSDoc comment. This is an internal compiler option; use at your own risk, because the compiler does not check that the result is valid.

However, we could look at using another tool to remove them:

If you are searching for a tool to handle additional levels of visibility within your d.ts files, look at api-extractor.

Also, the types that are used solely for driving return value inference should be marked as @internal, too. Even though we're exporting the, I think we should reserve the right to modify their implementations or rename them, etc.

@tmair
Copy link
Contributor

tmair commented Oct 3, 2020

Out of curiosity I had a look at the api-extractor tool. I noticed one limitation that could limit its use within the rxjs project:

The .d.ts rollup feature currently assumes that your package has a single entry point (the mainEntryPointFilePath setting).

Further explanation can be fount at the documentation and in the feature request microsoft/rushstack#664

It is possible to do an API Explorer rollup pass per entry point, but for example the Observable class declaration will not be referenced from the rxjs/operators enrty point to be imported from the rxjs entry point but included in the rollup d.ts bundle.

@benlesh
Copy link
Member

benlesh commented Oct 15, 2020

FWIW: They should also be renamed to have an _name underscored name, so people who aren't using TypeScript will have a cue that it's internal as well. Love it or hate it, that's a been a standard forever, and it's embarrassing that we haven't followed that, IMO.

@benlesh
Copy link
Member

benlesh commented Oct 15, 2020

I'd actually prefer that we just protected or private some _properties whenever possible. Now is the time, IMO.

@cartant
Copy link
Collaborator Author

cartant commented Oct 16, 2020

For context, I'd like the @internal attributes to be added - in addition to a leading underscore - because they are easy to enforce with a lint rule. And it's possible to have protected properties that are also internal - there are a bunch in Subject. I'm not advocating adding tooling to mess with the .d.ts 'cause tooling is a PITA.

@JannesMeyer
Copy link

I think it would be fine to use @internal because TypeScript itself uses it all over its own codebase. Take a look at this file for example: https://github.com/microsoft/TypeScript/blob/master/src/compiler/corePublic.ts (there are many more)

The warning in the docs is about the fact that you can create a situation where you mark things as internal that might be needed in another place, that you haven't marked as internal.

Example:

function foo(bar: Bar) {
    console.log(bar);
}

/* @internal */
class Bar() {

}

In this case foo() is public, but the API doesn't provide you with a way to create a Bar object, so it's unusable.

@benlesh
Copy link
Member

benlesh commented Nov 17, 2020

Also: There are @deprecated APIs that should really be @internal

@kwonoj kwonoj added the TS Issues and PRs related purely to TypeScript issues label Jan 22, 2021
@cartant
Copy link
Collaborator Author

cartant commented Apr 30, 2021

Closed by #6215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TS Issues and PRs related purely to TypeScript issues
Projects
None yet
Development

No branches or pull requests

5 participants