microsoft / rushstack

Monorepo for tools developed by the Rush Stack community
https://rushstack.io/
Other
5.76k stars 588 forks source link

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

Open dtinth opened 2 years ago

dtinth commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Related issues:

ivancuric commented 2 years ago

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 }
xiasun commented 2 weeks ago

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 }

Still have the same problem ...