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

Type issues with Unmanaged<T, RequiredProperties> #6037

Open
Yupeng-li opened this issue Aug 3, 2023 · 6 comments · May be fixed by #6943
Open

Type issues with Unmanaged<T, RequiredProperties> #6037

Yupeng-li opened this issue Aug 3, 2023 · 6 comments · May be fixed by #6943

Comments

@Yupeng-li
Copy link

Yupeng-li commented Aug 3, 2023

How frequently does the bug occur?

Always

Description

When using Realm classes, we noticed a few type issues all related to Unmanaged<T, RequiredKeys>.

  1. When specifying the RequiredProperties in Realm.Object<T, RequiredProperties>, the properties of type Realm.List or Realm.Dictionary are not allowed.
  2. If RequiredProperties is not provided when defining the class, the constructor accepts string as values.
  3. Unmanaged nested Realm.Object is not allowed in Realm.create. It's also reported in Unmanaged type doesn't cascade through links #5940

The details are available in the mini repo I attached.

If anyone is interested, I made a patch to resolve the issue 1 & 3 for now. https://gist.github.com/Yupeng-li/655eaf75f46086c4345a78e27dfa3c5e

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

Please check this codesandbox mini repo for details. (Please ignore the browser view on the right hand side. )

Version

11.7 & 11.9

What services are you using?

Local Database only

Are you using encryption?

Yes

Platform OS and version(s)

All

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

@takameyer
Copy link
Contributor

@Yupeng-li Thanks for reporting this and for providing a reproduction and workaround! I'll take a look at your suggestions and decide how best to move forward.

@edhage
Copy link

edhage commented Feb 24, 2024

Is this solved yet, I have the same problem. In fact the example https://github.com/mongodb-industry-solutions/Vehicle-Digital-Twin-Feedback-Loop is not working because of this.

@kneth
Copy link
Contributor

kneth commented Jun 11, 2024

@edhage I believe it hasn't been solve yet

@liamjones
Copy link

@kraenhansen apologies for tagging you again 🙏

Yupeng is on holiday and I'm working on updating his 11.1.0 type patch for (https://gist.github.com/Yupeng-li/655eaf75f46086c4345a78e27dfa3c5e) so it works on 12.14.0 so we can get our Realm upgraded.

I thought I'd try doing the update as a PR so it gets back into the project but I'm having some issues working out how to run the type testing.

I've followed CONTRIBUTING.md to clone main and run the @realm/node-tests tests, it all passes.

I've found packages/realm/type-tests/type-tests.ts, which looks like the file I want to edit to confirm my changes are good, but I'm unsure how to exercise this file from the npm scripts. I've not found info in the contrib docs.

It looks like it might be:

  • npm run --workspace realm check-types which runs and passes but doesn't fail if I put a deliberate type error into type-tests.ts
  • npm run --workspace realm test:types which runs but fails without me making any edits w/ about 900 errors

Any pointers would be appreciated! 😄

@kraenhansen
Copy link
Member

apologies for tagging you again 🙏

No worries, tag all you want 🙂 Especially if you're contemplating authoring a PR 😉

  • We're using the @internal TS annotation to strip out internal parts of the SDK from the public types and the check-types is mainly to ensure we're not exporting types which depend on other types that are stripped from the "public" interface.
  • We used test:types while we did the v11 → v12 rewrite of the SDK, but it seems it's now broken (likely beyond repair).

I think your best bet for now is to build the integration tests package in the hopes that the type utility is used in some test that would fail the build if the type is broken:

npm run build --workspace @realm/integration-tests

@liamjones
Copy link

npm run build --workspace @realm/integration-tests

That doesn't work, unfortunately. It doesn't look like anything exercises type-tests.ts anymore. I've written garbage to it and done a complete npm run build and it finishes without complaints.

If I break Unmanaged.ts though the integration tests do fail so that's helpful at least.

I think I might be able to resurrect type-tests.ts in a useful manner...

@liamjones liamjones linked a pull request Dec 6, 2024 that will close this issue
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants