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
Realm.List subscript accessor ([]
) has incorrect return type
#4750
Comments
@myou11 Thank you for reporting. As both |
After studying it a bit more careful, I think the type is correct. From the discussion, it is on purpose that |
Thanks for looking into this @kneth! I appreciate the linking to that Typescript discussion. After reading it, I understand why they have the return type as just |
Just to be clear, you only want it for The rationale behind our current types is to promote that you guard against out-of-range situations. It means, accessing an element should never return |
After re-visiting this, the types provided are good! For my use case before, I was already having checks to guard against out-of-range situations. I realize enabling the You can disregard this issue. Thanks for the discussion! |
How frequently does the bug occur?
All the time
Description
The return type for subscript access on a Realm.List seems to be incorrect. In the index.d.ts from the realm package, the definition of the subscript access is:
I think the return type should be
T | undefined
since specifying ann
that is out of bounds does produce anundefined
result.Stacktrace & log output
No response
Can you reproduce the bug?
Yes, always
Reproduction Steps
No response
Version
10.20.0-beta.5
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
iOS 15
Build environment
Which debugger for React Native: ..
Hermes
Cocoapods version
1.11.2
The text was updated successfully, but these errors were encountered: