CREATE TABLE producers
( id INT UNIQUE NOT NULL
, title TEXT NOT NULL
, phone TEXT NOT NULL
, address TEXT NOT NULL
, city TEXT NOT NULL
, zip_code TEXT NOT NULL
)
And this code produces a typescript error(TS2344):
interface ProducerRecord {
id: number
title: string
phone: string
address: string
city: string
zip_code: string
}
export function fetchProducer(id: number) {
const stmt = db.prepare(
'SELECT * FROM producers WHERE id=?;'
)
const datum = stmt.get<ProducerRecord>(id)
if (datum) {
return {
...datum,
address: datum.address ? datum.address.split('\n') : []
}
}
return null
}
This is the error I get:
error: TS2344 [ERROR]: Type 'ProducerRecord' does not satisfy the constraint 'Record<string, unknown>'.
Index signature for type 'string' is missing in type 'ProducerRecord'.
const datum = stmt.get<ProducerRecord>(id)
If I ignore this statement with:
// @ts-ignore
const datum = stmt.get<ProducerRecord>(id)
It works.
yet the documentation suggests that this is what is expected .
I have this table:
And this code produces a typescript error(TS2344):
This is the error I get:
If I ignore this statement with:
It works.
yet the documentation suggests that this is what is expected .
Did I miss something ?