Optional properties are ignored
See original GitHub issueThe following code in C # …
public int? ParentId { get; set; }
… results in the following in Typescript …
parentId: number;
… while the correct one should be:
parentId?: number;
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
In typescript, in a typed function argument, optional ...
I'm trying to create a router initialiser with a nice typed DX in typescript. My goal is to allow the developer to define...
Read more >Optional properties should be ignored when inferring K in ...
#14295 and Pick turns optional parameters into required ones when union types are used #20722 look similar but appear to be about Pick...
Read more >How to ignore properties with System.Text.Json
To ignore individual properties, use the [JsonIgnore] attribute. The following example shows a type to serialize. It also shows the JSON output:.
Read more >Entity Properties - EF Core
A property is considered optional if it is valid for it to contain null . If null is not a valid value to...
Read more >Optional property declarations should not use both '?' and ' ...
Optional property declarations should not use both '?' and 'undefined' syntax ... Use optional property syntax for properties holding some additional information.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry for hijacking the thread, but I’m looking to replace TypeWriter because it doesn’t handle nullable reference types in C#. Judging by this thread, TypeGen doesn’t automatically translate C# nullables into TS optionals. Is it a simple thing to configure it to do that?
Also bumping old thread sorry^^
Would love a way to make C# nullable types optional TS properties. I’ve set up
csNullableTranslation
toundefined
which is correctly generating the union typeT | undefined
, however this means you still have to manually specify these properties as undefined when creating these objects.becomes
and now for ever car I define, I must do
whereas I would prefer to define all cars without sunroofs like:
(imagine there are many of these properties which can optionally be used in different situations, and currently I have to set every one of them as undefined).
I’d prefer not to instrument many many C# classes / properties with TypeGen attributes, and instead base it from our existing nullable properties. (I did try the attribute but it didn’t seem to actually work - perhaps because I am using a GenerationSpec? I’m also unable/unwilling to manually set properties as optional in the spec due to there being way too many / not wanting a giant blog of config)
Any other workarounds to suggest? EDIT: and if this isn’t possible, is this something you would be open to supporting if I put together a PR? (either as a new config option, or a new value for
csNullableTranslation
)