I am currently working on a React Native project, but I have a TypeScript query. The SQLite embedded database is set up and I am trying to retrieve the entire array of rows. However, I am facing an issue with the object structure.
https://i.sstatic.net/74gFW.png
The problem lies in the fact that _array
is supposed to be private and is not included in the type definition. The existing type definitions are as follows:
export interface SQLResultSet {
insertId: number;
rowsAffected: number;
rows: SQLResultSetRowList;
}
export interface SQLResultSetRowList {
length: number;
item(index: number): any;
}
I have brainstormed three potential solutions, but none of them seem perfect:
- Casting
SQLResultSet.rows
asany
, which would result in losing type checking. - Utilizing the
length
property to callSQLResultSet.rows.item()
iteratively in order to construct the array (although this approach feels messy). - Creating my own interface that extends
SQLResultSetRowList
to include the_array: any[]
field, which is what I am currently doing to maintain type checks.
However, I am interested in whether there is a TypeScript syntax that allows for handling a function defined as item(index: number): any;
to easily convert it into an array.