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

Lack of nullability of reference types #3041

Open
charlesroddie opened this issue Jan 1, 2025 · 3 comments
Open

Lack of nullability of reference types #3041

charlesroddie opened this issue Jan 1, 2025 · 3 comments
Assignees

Comments

@charlesroddie
Copy link

Describe the bug

Properties that should be nullable are not listed as nullable if they are reference types.
For example, in a session s, s.AmountTotal is correctly Nullable<int64>, but s.ClientReferenceId is a string when it should be a string?.
Discrepancy between:

Presumably this library was never updated to support nullable reference types.

I would estimate it would take 2x longer to write dotnet code without nullable reference types, since for every use of a property you would need to refer to the online documentation to see if it is nullable or not and add manual casts to nullable before proceeding.

To Reproduce

  1. Get a Session s
  2. Type s.ClientReferenceId
  3. The result is a string

Expected behavior

The result should be a string?.

Code snippets

No response

OS

Windows

.NET version

dotnet9

Library version

current

API version

current

Additional context

No response

@jar-stripe
Copy link
Contributor

Hi @charlesroddie , so sorry for the delay in getting back to you! Thanks for filing this issue. We've been discussing internally and are trying to figure out the best way to support this. Unfortunately, there are some cases where nullable reference types can cause issues in our SDKs, so one option on the table would be to include optionality in the property doc string. Would that help you avoid having to switch to external documentation in the situation you describe?

@jar-stripe jar-stripe self-assigned this Jan 14, 2025
@charlesroddie
Copy link
Author

Thanks for the reply. Your suggestion would be helpful but is more of a stopgap. The expectation these days is that nullables are annotated, which has been a great step towards making dotnet type-safe. Libraries update at different speeds and I would perhaps focus on doing this in the medium-term rather than making a quick workaround. I would be surprised if there were insuperable technical problems around doing this.

@jar-stripe
Copy link
Contributor

@charlesroddie thanks for the feedback, and totally understand. We have some patterns in the SDK -- returning deleted resources into the same objects that are used to represent active resources, for example -- that make this harder than you think; either the non-nullable types would be unreliable, or every reference would have to be marked nullable. Neither seems particularly ergonomic, so a stopgap like this may be what we have to work for the short/medium term, unfortunately.

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

No branches or pull requests

2 participants