Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'RowDataPacket[] | RowDataPacket[][] | OkPacket | OkPacket[] | ResultSetHeader'. Property '0' does not exist on type 'RowDataPacket[] | RowDataPacket[][] | OkPacket | OkPacket[] | ResultSetHeader'. When trying to access any index of the result parameter in the callback
See original GitHub issueHi there so I have this code
static async getById(id: string): Promise<Business> {
return new Promise((resolve, reject) => {
connection.execute(
"SELECT * FROM business WHERE ID = ?;",
[id],
(err, result) => {
if (err) reject(err);
const { id, name, email, password }: {id: string, name: string, email: string, password: string} = result[0]; //it complains here
resolve({
id,
name,
email,
password,
});
}
);
});
}
And I have typescript giving me this error:
Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'RowDataPacket[] | RowDataPacket[][] | OkPacket | OkPacket[] | ResultSetHeader'.
Property '0' does not exist on type 'RowDataPacket[] | RowDataPacket[][] | OkPacket | OkPacket[] | ResultSetHeader'.ts(7053)
And I’m really not sure what to be doing here because I can’t change return type of result
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
The type error about the return of mysql2/promise query
TS7053: Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'RowDataPacket[] | RowDataPacket[][] | ...
Read more >element implicitly has an 'any' type because ... - You.com
TS7053: Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'MathType'. Property '0' does not...
Read more >How to access a RowDataPacket object | Edureka Community
I'm currently developing a desktop application with Node-webkit. During that process I need to get some data from a local MySQL-database.
Read more >TypeScript errors and how to fix them
If you want to support multiline text, then you would have to use string ... error TS1055: Type ' AxiosPromise ' is not...
Read more >Node.js MySQL SELECT FROM Query Examples - Tutorial Kart
js program to access data of a MySQL Table. MySQL SELECT Query is used to get one or more rows from MySQL Table....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m using
.execute<RowDataPacket[]>(...)
for single-statementselect
s. Similarly, multi-statement selects would have.execute<RowDataPacket[][]>(...)
.I don’t know whether the right type for
insert
s,update
s,create
s etc. isResultSetHeader
(which I’m getting in practice) orOkPacket | ResultSetHeader
, though.+1, also an issue here got around it by typecasting, but I don’t know the library/mysql well so it’s not ideal.
this is with “mysql2/promise”