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

[api-extractor] handle merged (augmented) symbols properly #1045

Closed
shlomiassaf opened this issue Jan 21, 2019 · 4 comments
Closed

[api-extractor] handle merged (augmented) symbols properly #1045

shlomiassaf opened this issue Jan 21, 2019 · 4 comments
Labels
enhancement The issue is asking for a new feature or design change needs more info We can't proceed because we need a better repro or an answer to a question

Comments

@shlomiassaf
Copy link

shlomiassaf commented Jan 21, 2019

When declaration merging is applied on an imported type a new symbol is created (merged symbol).

This symbol contains SymbolFlags.Transient which does not have a matching AstSymbol which in turn throws an error

import { RowContext } from '@angular/cdk/table';
export interface MyExtender extends RowContext<any> {}

declare module '@angular/cdk/table/typings/table.d' {
  interface RowContext<T> {
      myAugmentedProp: string;
  }
}

The type itself is fine, it is just a merged type and the transient check should not stop it, for this particular situation.

This is my current workaround, i'm not sure it covers all scenarios:

import { AstSymbolTable } from '@microsoft/api-extractor/lib/analyzer/AstSymbolTable';

const { _fetchAstSymbol } = AstSymbolTable.prototype as any;

(AstSymbolTable.prototype as any)._fetchAstSymbol = function (followedSymbol, addIfMissing, astImportOptions, localName) {
  let result = _fetchAstSymbol.call(this, followedSymbol, addIfMissing, astImportOptions, localName);

  if (!result && astImportOptions && followedSymbol.flags & ts.SymbolFlags.Transient) {
    followedSymbol.flags = followedSymbol.flags ^ ts.SymbolFlags.Transient;
    result = _fetchAstSymbol.call(this, followedSymbol, addIfMissing, astImportOptions, localName);
    followedSymbol.flags = followedSymbol.flags | ts.SymbolFlags.Transient;
  }

  return result;
};
@octogonz
Copy link
Collaborator

Could you provide a branch with a simple project that repros this error? I have never encountered transient symbols in any of our projects at work, so I'm pretty unfamiliar with this feature (or why anyone would want it heheh). Thanks!

@octogonz octogonz added enhancement The issue is asking for a new feature or design change needs more info We can't proceed because we need a better repro or an answer to a question labels Jan 27, 2019
@shlomiassaf
Copy link
Author

@octogonz I'll do that shortly...

Augmenting types is quite common, especially with plugin architecture and type lookup maps.

Anyway, the transient type is created by TS and represents the merged (union) type of the original type and the augmentation type...

@octogonz
Copy link
Collaborator

Does the transient type have the same signature for every source file that references it? Or does it create a special extended signature that is only visible in the source file that contains the merged declaration? In the latter case, API Extractor would need to somehow distinguish the two different RowContext signatures, and have different names for them.

@octogonz
Copy link
Collaborator

Closing, since this is a duplicate of #1709 which has made more progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is asking for a new feature or design change needs more info We can't proceed because we need a better repro or an answer to a question
Projects
None yet
Development

No branches or pull requests

2 participants