rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[api-extractor] API Extractor appends `_2` some names in doc model

Open dtinth opened this issue 2 years ago • 3 comments

Summary

I am trying to generate a doc model for a TypeScript library. I found that some names in the resulting documentation has _2 added to it.

/** @public */
export declare function invariant(value: any, format?: string, ...extra: any[]): void;

The generated documentation model specified the function name as "invariant_2" instead of just "invariant".

Repro steps

gh repo clone dtinth/repro-api-extractor-issue-2895
cd repro-api-extractor-issue-2895
yarn
yarn test

Expected result: The included test in the repro, validate.js, is passing.

Actual result: It fails here:

assert.equal(api.members[0].members[0].name, 'invariant')
// => AssertionError [ERR_ASSERTION]: 'invariant_2' == 'invariant'

Details

An npm package @types/invariant is installed in package.json, which happens to have the same name as a function:

{
  "devDependencies": {
    "@microsoft/api-extractor": "^7.18.7",
    "@types/invariant": "^2.2.35",
    "invariant": "^2.2.4"
  }
}

If I remove "@types/invariant" then the issue does not happen.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-extractor version? 7.18.7
Operating system? Mac
API Extractor scenario? .api.json
Would you consider contributing a PR? Maybe
TypeScript compiler version? 4.3.5
Node.js version (node -v)? 14.17.5

dtinth avatar Sep 08 '21 05:09 dtinth

Workaround

Just remove _2 from .api.json file. Here’s an example shell script that you can rush after running api-extractor

#!/bin/bash -e
# A weird issue with API Extractor adds `_2` suffix to some function names.
# See: https://github.com/microsoft/rushstack/issues/2895
sed -i.bak 's/_2//g' temp/package-name.api.json

dtinth avatar Oct 14 '21 16:10 dtinth

Related issues:

  • #2534
  • #2479

dtinth avatar Jan 17 '22 08:01 dtinth

Noticed the same thing in some interfaces and enums:

declare enum ImageOrientation_2 {
 // ...
}
export { ImageOrientation_2 as ImageOrientation }

declare enum DocumentType_2 {
// ...
}
export { DocumentType_2 as DocumentType }

ivancuric avatar Jul 14 '22 12:07 ivancuric