Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Realm JS Typescript: type for Realm.Results

$
0
0

I'm using Realm JS for a React-Native app written in TypeScript and I'm wondering about the typing of Realm.Results.

here is my use case:

My Schema for 'MessageData' is:

export const MessageDataSchema = {  name: 'MessageData',  primaryKey: 'id',  properties: {  id: 'string',  messages: { type: 'list', objectType: 'Message' },  }}

Here is the typing is use to fetch data from the database (fetches the MessageData of a particular conversation, with its conversationId).

const databaseMessages: Realm.Results<MessageData> = realm.objectForPrimaryKey<Realm.Results<MessageData>>('MessageData', conversationId)

With this type, I get an error further down my code when I add a listener to the database:

Property 'messages' does not exist on type 'Results'.ts(2339)

databaseMessages.addListener(() => {setMessages([...databaseMessages.messages]);});

any thoughts why this might be happening? thanks a lot!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>