-
Notifications
You must be signed in to change notification settings - Fork 608
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] .d.ts rollup sometimes emits names that conflict with global names #1095
Comments
In typescript.d.ts I found this interface, which checks whether a name is global or not: interface PrintHandlers {
/**
* A hook used by the Printer when generating unique names to avoid collisions with
* globally defined names that exist outside of the current source file.
*/
hasGlobalName?(name: string): boolean; However, it is a contract meant to be implemented by the caller of the namespace ts {
. . .
export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker {
. . .
const globals = createSymbolTable();
. . .
const checker: TypeChecker = {
. . .
hasGlobalName
. . .
};
. . .
return checker;
. . .
function hasGlobalName(name: string): boolean {
return globals.has(escapeLeadingUnderscores(name));
} But when I try to use |
The From any source file, you can enumerate this.typeChecker.getSymbolsInScope(sourceFile, ts.SymbolFlags.Transient) ...however I'm pretty sure there exist global symbols that are not "transient", as well as "transient" symbols that are not global names. The compiler docs don't say much about what "transient" actually means besides this, but it sounds like the wrong concept for what we need: export const enum SymbolFlags {
. . .
Transient = 1 << 25, // Transient symbol (created during type check) @RyanCavanaugh @DanielRosenwasser any idea how to find the global names? For example, is there any example anywhere of someone implementing the |
Okay, I found several internal APIs that can be combined together to reach const typeChecker = (this.program as any).getDiagnosticsProducingTypeChecker();
const resolver = (typeChecker as any).getEmitResolver();
resolver.hasGlobalName('Promise'); // --> true Is this a valid/safe solution? |
Hmm... the symbol table being queried by Besides
|
[api-extractor] Temporary workaround for issue #1095
@octogonz that's correct. The global symbol table has everything you could reach from an unqualified position (Partial, encodeURI, etc) as well as all module names you could import without path qualification ("https", etc). |
@RyanCavanaugh Welcome back, BTW! 😄 |
I'm looking at implementing this now. Is I noticed this slightly concerning comment: // For testing purposes only. Should not be used by any other consumers (including the
// language service).
/* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker; |
Fixed by PR #1767 which was published with API Extractor 7.7.12. |
* add @microsoft/api-extractor to botbuilder-core * add api-extractor to libraries * run api-extractor on all libs except for: * botframework-connector * adaptive-expressions (in preview) * botbuilder-lg (in preview) * support friendlier jsonc render on GitHub * bump @microsoft/api-extractor to ^7.7.12 b/c microsoft/rushstack/issues/1095 * regenerate bf-schema.api.md after master merge * add codeowners, regen core & dialogs api.md * regenerate botbuilder.api.md after merging master
…hardcoded list of common names
Consider this example:
In the .d.ts rollup,
p1
andp2
accidentally end up with the same type:This happens because the algorithm doesn't realize that
Promise
is a global name introduced by lib.es2015.promise.d.ts, which comes in via this part of tsconfig.json:This is breaking @microsoft/sp-application-base.
@iclanton
The text was updated successfully, but these errors were encountered: