Skip to content

[api-extractor] Type members #3289

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

chadhietala
Copy link
Contributor

@chadhietala chadhietala commented Mar 22, 2022

Summary

This supersedes #3003 but only does so for simple type aliases (no type algebra)

Details

See #3002

How it was tested

I extended the example projects to confirm that only simple type aliases get expanded out

@chadhietala
Copy link
Contributor Author

@octogonz any chance you can review this?

@chadhietala chadhietala changed the title Type members [api-extractor] Type members Apr 4, 2022
@iclanton
Copy link
Member

iclanton commented Apr 9, 2022

Note: PR #3337 has renamed our GitHub master branch to main. This should not affect your pull request, but we recommend to redo your git clone to avoid confusion with the old branch name.

@chadhietala
Copy link
Contributor Author

@iclanton or @octogonz any chance you can take a look at this?

Copy link
Contributor

@zelliott zelliott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more additional comments:

  1. I think we'll need to bump the .api.json version in DeserializerContext.ts.
  2. Can we update the comment at
    * Represents a TypeScript property declaration that belongs to an `ApiInterface`.
    to reflect that ApiPropertySignature items are no longer unique to ApiInterface containers? I think there are a few additional API items that need to have comments updated as well (e.g. ApiMethodSignature, ApiConstructSignature, etc).

@@ -256,7 +257,8 @@ export class MarkdownDocumenter {
this._writeEnumTables(output, apiItem as ApiEnum);
break;
case ApiItemKind.Interface:
this._writeInterfaceTables(output, apiItem as ApiInterface);
case ApiItemKind.TypeAlias:
this._writeItemContainerTables(output, apiItem as ApiItemContainerMixin);
Copy link
Contributor

@zelliott zelliott Jun 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some initial confusion here because this method is called writeItemContainerTables, and yet only ApiInterface and ApiTypeAlias items use it (not other item containers like ApiClass or ApiEnum). Maybe we could rename this method to writeInterfaceOrTypeAliasTypes to align with the writePackageOrNamespaceTables below?

*/
private _writeInterfaceTables(output: DocSection, apiClass: ApiInterface): void {
private _writeItemContainerTables(output: DocSection, apiClass: ApiItemContainerMixin): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the second parameter to be apiInterfaceOrTypeAlias: ApiInterface|ApiTypeAlias? (I know that the parameter name being incorrect is preexisting).

@@ -934,6 +934,13 @@ export class ApiModelGenerator {

parentApiItem.addMember(apiTypeAlias);
}

if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% confident about this, but don't we only want to process child declarations if apiTypeAlias === undefined? (i.e. move this chunk into the if block above)


if (
ts.isTypeAliasDeclaration(astDeclaration.declaration) &&
ts.isTypeLiteralNode(astDeclaration.declaration.type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me from line 940 which type aliases will have their children processed and which will not. I think a comment providing some supported vs not supported examples could go a long way here.

/**
* @public
*/
export type MyUnionType =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type alias will not have its members documented, correct? If that's the case, can we say so in its doc comment to make it clear to readers what this type alias is testing?

@@ -0,0 +1,9 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the api-extractor-scenarios/apiItemKinds test project could be a better fit for this test case. In the past, I've used the api-extractor-scenarios project to hold different test cases that don't require a standalone project set up. We could create a new file called typeAliases.ts there, and add some supported vs unsupported type alias examples. I think the api-extractor-test-01 test project tests something very specific (despite its ambiguous name). WDYT?

{
"packageName": "@microsoft/api-extractor-model",
"comment": "Support documenting members of type aliases",
"type": "patch"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this add new functionality and thus this should be minor (same for the other two changelog files)? Can we also clarify in the change comment that this only supports documenting members of a very simple shape of type alias?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: AE/AD
Development

Successfully merging this pull request may close these issues.

4 participants