Add nullable strategy (null/undefined) support - #284
Open
gluschenko wants to merge 1 commit into
Open
gluschenko wants to merge 1 commit into
gluschenko wants to merge 1 commit into
Conversation
Introduce a NullableStrategy option and propagate it through the CLI and transpilation options so generated TypeScript can use either `undefined` (default) or `null` for nullable members. Adds a --nullable CLI flag, a NullableStrategy enum, and helper methods (GetNullableUnionLiteral, UseOptionalPropertyForNullableReferenceTypes) on ITranspilationOptions. Type mappers (NullableStructTypeMapper, TupleTypeMapper) and the message type translator now respect the chosen strategy by emitting either optional properties or explicit unions with `null`. README updated with usage and examples, and unit tests added to verify `null` emission for tuples and nullable reference types.
Author
|
Relates to: |
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.
This pull request introduces a new option to control how nullable types are represented in the generated TypeScript code. Users can now choose between representing nullable members with
undefined(the previous default) or withnull. This affects both the CLI, the code generation logic, and is reflected in the documentation and tests.Nullable Type Representation Support
--nullableCLI option to select betweenundefinedandnullfor representing nullable members in generated TypeScript code. The default remainsundefined, but users can now opt-in to explicitnullunions. (README.md,src/Tapper.Generator/App.cs)TranspilationOptions,ITranspilationOptions) and code generation logic to support and propagate the newNullableStrategysetting throughout the transpilation process. (src/Tapper/ITranspilationOptions.cs,src/Tapper/TranspilationOptions.cs)| undefinedor| null) or optional property marker based on the selected nullable strategy. (src/Tapper/TypeMappers/NullableStructTypeMapper.cs,src/Tapper/TypeMappers/TupleTypeMapper.cs,src/Tapper/TypeTranslators/DefaultMessageTypeTranslator.cs)Documentation and Usability
README.mdto document the new--nullableoption, including usage examples and the effect on generated TypeScript code. Also clarified the TypeScript mapping forSystem.Nullable<T>.Testing
nullunions when theNullableStrategy.Nulloption is used. (tests/Tapper.Tests/InheritanceTests.cs,tests/Tapper.Tests/TupleTest.cs) Introduce a NullableStrategy option and propagate it through the CLI and transpilation options so generated TypeScript can use eitherundefined(default) ornullfor nullable members. Adds a --nullable CLI flag, a NullableStrategy enum, and helper methods (GetNullableUnionLiteral, UseOptionalPropertyForNullableReferenceTypes) on ITranspilationOptions. Type mappers (NullableStructTypeMapper, TupleTypeMapper) and the message type translator now respect the chosen strategy by emitting either optional properties or explicit unions withnull. README updated with usage and examples, and unit tests added to verifynullemission for tuples and nullable reference types.