Repository navigation
Export TypeScript namespace when ExportTypes is enabled - #5402
Open
mario-ruiz22 wants to merge 2 commits into
Open
mario-ruiz22 wants to merge 2 commits into
mario-ruiz22 wants to merge 2 commits into
Conversation
|
We've tested this change internally and it has unblocked our conversion to Angular 22 which uses TypeScript 6. Thanks for considering it! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When generating TypeScript with
/namespace:, the generatednamespace X { ... }block never gets theexportkeyword, even whenExportTypesistrue. That means the namespace can't be imported by consumers at all.The
modulebranch inFile.liquidalready gates itsexportkeyword onExportTypes. Thenamespacebranch right below it never did. This PR bringsnamespacein line withmodule.Why
ExportTypesis the existing setting for controlling whether generated declarations get exported. Every other top-level declaration inFile.liquid(classes, interfaces, themoduleblock) already respects it.namespacewas the one place this got missed. Gating onExportTypesinstead of always exporting keeps the option open for consumers who load the output as a plain script instead of a module.Why not just use
/moduleName:instead, since it already exports? Because it emits themodulekeyword, which TypeScript 6.0+ hard-deprecates and errors on (TS1540). SomoduleNameisn't a real alternative for anyone on TypeScript 6.0+.Breaking changes
None functionally, but output changes for most
/namespace:users:ExportTypesdefaults totrue, so the generatednamespaceblock will now includeexportby default (it never did before, regardless ofExportTypes). If you explicitly set/exportTypes:false, nothing changes.Verification
CodeGenerationTests.cs,When_namespace_is_set_then_namespace_is_exported_based_on_export_types, coveringExportTypestrue and false. Both cases pass and compile the generated output viaTypeScriptCompiler.AssertCompile./namespace:, so none are affected. The actual output diff (namespace X {vsexport namespace X {) is checked directly in the new test's assertions, and reviewed again by hand in the manual real-spec verification below.NSwag.ConsoleCorefrom this branch and ranopenapi2tsclientwith/namespace:against a real internal spec. Output now compiles and imports correctly, where it previously failed withTS2459.Documentation and samples updated. Not needed for this change. See the TypeScriptGeneratorSettings wiki page for the related settings.