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

How do I get all items in the array that is type defined as item(index: number): any;

$
0
0

I'm working on a react native project but this is more of a typescript question. I have the SQLite embedded db wired up and I want to retrieve the whole array of rows. The problem is that the object looks like this

enter image description here

So as you can see _array is meant to be private and is not included in the type definition. The type definitions are like so

export interface SQLResultSet {  insertId: number;  rowsAffected: number;  rows: SQLResultSetRowList;}export interface SQLResultSetRowList {  length: number;  item(index: number): any;}

I've come up with three solutions but I'm not totally happy with any of them.

  1. Casting SQLResultSet.rows as any (worse option as I lose my type checking).
  2. Using the length property to make calls to SQLResultSet.rows.item(), iterating over all of them and building the array from there (also not ideal because it's extra code that feels messy).
  3. Making my own interface extending SQLResultSetRowList to add the _array: any[] field (what I'm currently doing and at least I don't lose my type checks with that).

But, ideally, I want to know if there is some typescript syntax for working with a function as it's defined in item(index: number): any; where I can simply get that all as an array.


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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