Closed angelos3lex closed 2 months ago
@angelos3lex What about:
import Realm, {Results} from 'realm';
public createQuery<T>(schema: string): Results<T> {
return this._realm.objects<T>(schema); // <- forward the generic
}
Does that work?
@angelos3lex What about:
import Realm, {Results} from 'realm'; public createQuery<T>(schema: string): Results<T> { return this._realm.objects<T>(schema); // <- forward the generic }
Does that work?
If i use the Results i always get the error:
Type 'Results' is not generic.ts(2315)
That's why i use the Realm.Results
but then i get the error i sent above. Even if i propagate the <T>
inside this._realm.objects<T>(schema);
@angelos3lex same issue
I tried import Results
from @realm/react
it worked for me and I don't know why it is different when import from realm
or @realm/react
also I had checked in @realm/react
it's the same thing.
import { Realm, useQuery } from "@realm/react"
const getIcons = (icons: Realm.Results<Icon>) => {
// ...
}
const data = useQuery(....)
const icons = getIcons(data)
Your case:
import { Realm, useRealm } from "@realm/react"
const createQuery = <T>(schema: string): Realm.Results<Realm.Object<T> & T> => {
const realm = useRealm()
return realm.objects<T>(schema)
}
const icons = createQuery<Icon>("Icon")
icons.filtered('name TEXT $0', 'hunger')
I wonder if
import Realm, {Results} from 'realm';
public createQuery<T extends Realm.Object>(schema: string): Results<T> {
return this._realm.objects<T>(schema);
}
will be useful
@angelos3lex, the following should work for you:
import Realm from 'realm';
// ...
public createQuery<T>(schema: string): Realm.Results<RealmObject<T> & T> {
return this._realm.objects(schema);
}
How frequently does the bug occur?
Always
Description
Imagine i have the following code:
This growls (typescript 4.8.4) saying:
If i do:
I get ts error:
Type 'Results' is not generic. ts(2315)
According to the docs, it should be valid the Realm.Results type
Stacktrace & log output
No response
Can you reproduce the bug?
Always
Reproduction Steps
No response
Version
12.2.0
What services are you using?
Local Database only
Are you using encryption?
No
Platform OS and version(s)
android, iOS
Build environment
RN Version 0.72.5
Cocoapods version
No response