diff --git a/src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs b/src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs index 9debd754f4..4ed056a595 100644 --- a/src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs +++ b/src/Kiota.Builder/Writers/TypeScript/CodeFileDeclarationWriter.cs @@ -31,7 +31,17 @@ public override void WriteCodeElement(CodeFileDeclaration codeElement, LanguageW } ); conventions.WriteAutoGeneratedStart(writer); - _codeUsingWriter.WriteCodeElement(usings, ns, writer); + + // remove duplicate using, keep a single using for each internal type in the same namespace + var enumeratedUsing = usings.ToArray(); + var filteredUsing = enumeratedUsing.Where(x => x.IsExternal) + .Union(enumeratedUsing.ToArray() + .Where(x => x is { IsExternal: false, Declaration.TypeDefinition: not null }) + .GroupBy(x => + $"{x.Declaration!.TypeDefinition!.GetImmediateParentOfType().Name}.{x.Declaration?.Name.ToLowerInvariant()}") + .Select(x => x.First())); + + _codeUsingWriter.WriteCodeElement(filteredUsing, ns, writer); } }