Skip to content

Commit

Permalink
Merge pull request #4398 from sher/ts_ignore_imports
Browse files Browse the repository at this point in the history
Suppress errors in .ts files using ts-ignore
  • Loading branch information
baywet authored Mar 26, 2024
2 parents 9504993 + 7d0b0df commit 84eca00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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);
}
}

0 comments on commit 84eca00

Please sign in to comment.