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 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(); } 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); } }