Repository: microsoft/kiota (csharp)

Issue:
Unused type imports Parsable and ParsableFactory are causing build fail
Kiota generated request builder imports several types from abstractions package.
```ts
import { type BaseRequestBuilder, type Parsable, type ParsableFactory, type RequestConfiguration, type RequestInformation, type RequestsMetadata } from '@microsoft/kiota-abstractions';
```
Among them `Parsable` and `ParsableFactory` are never referenced in the generated code.
This is failing to build in projects where `tsconfig.json` has `noUnusedLocals: true` such as default Vitejs [tsconfig.json](https://github.com/vitejs/vite/blob/main/packages/create-vite/template-react-ts/tsconfig.json#L19).

Pull request:
Fixes https://github.com/microsoft/kiota/issues/4397

Added `// @ts-ignore` comment line as per [discussion](https://github.com/microsoft/kiota/issues/4397#issuecomment-2017963008) to suppress typecheck errors.

Currently, generated TypeScript `.ts` files contain imports that are never referenced in the code.
This causes TypeScript typecheck to fail in projects where `tsconfig.json` compiler option `noUnusedLocals: true` is set.
Example: Vitejs template [tsconfig.json](https://github.com/vitejs/vite/blob/main/packages/create-vite/template-react-ts/tsconfig.json#L19)

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e109a7f170..5ef449d8dd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Added a warning message in the CLI when using preview languages. [#4316](https://github.com/microsoft/kiota/issues/4316)
 - Added support for handling untyped Json content in C#,Golang, TypeScript and Java. [#2319](https://github.com/microsoft/kiota/issues/2319)
+- Added TypeScript typecheck suppression to `.ts` files where unused imports cause build fail in projects which use `noUnusedLocals: true` compiler option. [#4397](https://github.com/microsoft/kiota/issues/4397)
 
 ### Changed
 
@@ -96,7 +97,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed
 
-- Java -  Self-extraction of query parameters instead of using reflection. [#3965](https://github.com/microsoft/kiota/issues/3965)
+- Java - Self-extraction of query parameters instead of using reflection. [#3965](https://github.com/microsoft/kiota/issues/3965)
 - Fixed a bug where the discriminator validation rule would report false positives on nullable union types.
 - Fixed a bug where constructors and model names where clashing in Go. [#3920](https://github.com/microsoft/kiota/issues/3920)
 - Fixed a bug where the order of enum declaration might results in a missing enum type. [#3935](https://github.com/microsoft/kiota/issues/3935)
diff --git a/src/Kiota.Builder/Writers/TypeScript/CodeUsingWriter.cs b/src/Kiota.Builder/Writers/TypeScript/CodeUsingWriter.cs
index f205f4af2f..7fdbfd4ca0 100644
--- a/src/Kiota.Builder/Writers/TypeScript/CodeUsingWriter.cs
+++ b/src/Kiota.Builder/Writers/TypeScript/CodeUsingWriter.cs
@@ -26,7 +26,10 @@ public void WriteCodeElement(IEnumerable<CodeUsing> usings, CodeNamespace parent
                                                 .GroupBy(static x => x.Path)
                                                 .OrderBy(static x => x.Key);
         foreach (var codeUsing in importSymbolsAndPaths.Where(static x => !string.IsNullOrWhiteSpace(x.Key)))
+        {
+            writer.WriteLine("// @ts-ignore");
             writer.WriteLine($"import {{ {codeUsing.Select(static x => GetAliasedSymbol(x.Symbol, x.Alias, x.ShouldUseTypeImport)).Distinct().OrderBy(static x => x).Aggregate(static (x, y) => x + ", " + y)} }} from '{codeUsing.Key}';");
+        }
 
         writer.WriteLine();
     }


Test patch:
diff --git a/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeUsingWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeUsingWriterTests.cs
index 60cea77fa8..0071f095f6 100644
--- a/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeUsingWriterTests.cs
+++ b/tests/Kiota.Builder.Tests/Writers/TypeScript/CodeUsingWriterTests.cs
@@ -41,6 +41,7 @@ public void WritesAliasedSymbol()
         };
         usingWriter.WriteCodeElement(new CodeUsing[] { us }, root, writer);
         var result = tw.ToString();
+        Assert.Contains("// @ts-ignore", result);
         Assert.Contains("import { Bar as baz } from", result);
     }
     [Fact]
@@ -62,6 +63,7 @@ public void DoesntAliasRegularSymbols()
         };
         usingWriter.WriteCodeElement(new CodeUsing[] { us }, root, writer);
         var result = tw.ToString();
+        Assert.Contains("// @ts-ignore", result);
         Assert.Contains("import { Bar } from", result);
     }
 
@@ -86,6 +88,7 @@ public void WritesImportTypeStatementForGeneratedInterfaces()
         };
         usingWriter.WriteCodeElement(new CodeUsing[] { us }, root, writer);
         var result = tw.ToString();
+        Assert.Contains("// @ts-ignore", result);
         Assert.Contains("import { type Bar } from", result);
     }
 
@@ -109,6 +112,7 @@ public void WritesImportTypeStatementForDenotedExternalLibraries()
         };
         usingWriter.WriteCodeElement(new CodeUsing[] { us }, root, writer);
         var result = tw.ToString();
+        Assert.Contains("// @ts-ignore", result);
         Assert.Contains("import { type Bar } from", result);
     }
 
@@ -132,6 +136,7 @@ public void WritesImportTypeStatementForRequestConfiguration()
         };
         usingWriter.WriteCodeElement(new CodeUsing[] { us }, root, writer);
         var result = tw.ToString();
+        Assert.Contains("// @ts-ignore", result);
         Assert.Contains("import { type Bar } from", result);
     }
 
@@ -155,6 +160,7 @@ public void WritesImportTypeStatementForQueryParameters()
         };
         usingWriter.WriteCodeElement(new CodeUsing[] { us }, root, writer);
         var result = tw.ToString();
+        Assert.Contains("// @ts-ignore", result);
         Assert.Contains("import { type Bar } from", result);
     }
 
@@ -178,6 +184,7 @@ public void WritesImportTypeStatementForModel()
         };
         usingWriter.WriteCodeElement(new CodeUsing[] { us }, root, writer);
         var result = tw.ToString();
+        Assert.Contains("// @ts-ignore", result);
         Assert.Contains("import { type Bar } from", result);
     }
 }