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

Nullable properties in TsInterface annotated classes not exported as optional #83

Closed
takerukoushirou opened this issue Sep 27, 2018 · 3 comments
Assignees

Comments

@takerukoushirou
Copy link

I have the same problem as in issue #49, though with TsInterface annotated classes. I'm using .NET Core 2.1 with Reinforced Typings version 1.4.95.

Every nullable property (e.g. bool?) will not be exported as optional and I have to explicitly add [TsProperty(ForceNullable = true)].

Reinforced Typings configuration (no fluent configuration):

[assembly:
    TsGlobal(
        ExportPureTypings = true,
        WriteWarningComment = true,
        CamelCaseForMethods = true,
        CamelCaseForProperties = true,
        UseModules = true,
        DiscardNamespacesWhenUsingModules = true,
        GenerateDocumentation = true
    )]

with RtTargetFile and <RtDisable>false</RtDisable> project properties.

@chriskooken
Copy link

chriskooken commented Oct 12, 2018

@takerukoushirou I am having the same issue. But on [TsClass]

@pavel-b-novikov pavel-b-novikov self-assigned this Nov 21, 2018
@pavel-b-novikov
Copy link
Member

Well, actually it is really weird feature request since, AFAIK, every property in TS can be set to null - you do not need something special for that. ? with field actually means that field may be omitted when instantiating value of type.

From documentation:

These optional properties are popular when creating patterns like “option bags” where you pass an object to a function that only has a couple of properties filled in.

So .NET Nullable<> has different semantics since it has value/reference types separation. As result, some people insist that C# nullable properties must not be translated into TS optional properties, other people insist that they must.

In conclusion, I have decided to add AutoOptionalProperties parameter to [TsGlobal]/fluent configuration in order to satisfy both sides. If you want nullables to be translated into TS optionals, just turn AutoOptionalProperties on. By default it is off.

Made in version 1.5

@chriskooken
Copy link

Thanks so much, this solves another problem of mine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants