diff --git a/apps/api-extractor/src/analyzer/ExportAnalyzer.ts b/apps/api-extractor/src/analyzer/ExportAnalyzer.ts index 5268cc8eb16..f90db96bf45 100644 --- a/apps/api-extractor/src/analyzer/ExportAnalyzer.ts +++ b/apps/api-extractor/src/analyzer/ExportAnalyzer.ts @@ -265,7 +265,11 @@ export class ExportAnalyzer { : importOrExportDeclaration.moduleSpecifier; const mode: ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined = specifier && ts.isStringLiteralLike(specifier) - ? TypeScriptInternals.getModeForUsageLocation(importOrExportDeclaration.getSourceFile(), specifier) + ? TypeScriptInternals.getModeForUsageLocation( + importOrExportDeclaration.getSourceFile(), + specifier, + this._program.getCompilerOptions() + ) : undefined; const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule( @@ -905,7 +909,8 @@ export class ExportAnalyzer { ts.isStringLiteralLike(importOrExportDeclaration.moduleSpecifier) ? TypeScriptInternals.getModeForUsageLocation( importOrExportDeclaration.getSourceFile(), - importOrExportDeclaration.moduleSpecifier + importOrExportDeclaration.moduleSpecifier, + this._program.getCompilerOptions() ) : undefined; const resolvedModule: ts.ResolvedModuleFull | undefined = TypeScriptInternals.getResolvedModule( diff --git a/apps/api-extractor/src/analyzer/TypeScriptInternals.ts b/apps/api-extractor/src/analyzer/TypeScriptInternals.ts index eeb8e1b4df0..f3c771d9118 100644 --- a/apps/api-extractor/src/analyzer/TypeScriptInternals.ts +++ b/apps/api-extractor/src/analyzer/TypeScriptInternals.ts @@ -102,12 +102,13 @@ export class TypeScriptInternals { */ public static getModeForUsageLocation( file: { impliedNodeFormat?: ts.SourceFile['impliedNodeFormat'] }, - usage: ts.StringLiteralLike | undefined + usage: ts.StringLiteralLike, + compilerOptions: ts.CompilerOptions ): ts.ModuleKind.CommonJS | ts.ModuleKind.ESNext | undefined { // Compiler internal: // https://github.com/microsoft/TypeScript/blob/v4.7.2/src/compiler/program.ts#L568 - return (ts as any).getModeForUsageLocation?.(file, usage); + return ts.getModeForUsageLocation?.(file, usage, compilerOptions); } /** diff --git a/common/changes/@microsoft/api-extractor/fix-5.6_2024-10-14-19-47.json b/common/changes/@microsoft/api-extractor/fix-5.6_2024-10-14-19-47.json new file mode 100644 index 00000000000..a11c78a8580 --- /dev/null +++ b/common/changes/@microsoft/api-extractor/fix-5.6_2024-10-14-19-47.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/api-extractor", + "comment": "Fix a compatibility issue with usage of `getModeForUsageLocation` in TypeScript 5.6", + "type": "patch" + } + ], + "packageName": "@microsoft/api-extractor" +} \ No newline at end of file