Skip to content
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

Suppress errors in .ts files using ts-ignore #4398

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/Kiota.Builder/Writers/TypeScript/CodeUsingWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
}
Loading