I am creating a store with index that has a string type. Later, when I need to retrieve all values belonging to this index I get an error that the string type key is not allowed... But the code compiles and I see the correct results listed. So, there is probably something wrong with function parameter types.
Argument of type '"1"' is not assignable to parameter of type 'number | IDBKeyRange | null | undefined'.ts(2345)
As I mentioned - correct data is returned for the ID. So if I type "1" I get records with suid = '1' and if I type suid = '2' so this seems to be purely typescript type/interface error.
I have not checked but probably other functions are affected.
"idb": "^7.0.1",
side question
I also have a bonus question that maybe someone is able to answer. Is it possible to define 2 different interfaces - 1 for data insert and 1 for data retrieval? The ID (in my example sid ) is auto-generated property. So when I add the record - it is always NOT expected to be set (is optional). And when you retrieve the data - the property is always set.
Currently I use the same interface and this causes issues, because the code always assumes that the retrieved data for property sid could be null..
I know that I can probably use mapper to map the results to a new interface when data is retrieved, but maybe there is more elegant solution.. (p.s. typescript user day 1)
edit: actually, after giving it some thought I have done the following:
main issue/topic
I am creating a store with index that has a
string
type. Later, when I need to retrieve all values belonging to this index I get an error that thestring
type key is not allowed... But the code compiles and I see the correct results listed. So, there is probably something wrong with function parameter types.main code:
then we need to get the indexed data:
here I get the error:
As I mentioned - correct data is returned for the ID. So if I type "1" I get records with
suid = '1'
and if I typesuid = '2'
so this seems to be purely typescript type/interface error.I have not checked but probably other functions are affected.
side question
I also have a bonus question that maybe someone is able to answer. Is it possible to define 2 different interfaces - 1 for data insert and 1 for data retrieval? The
ID
(in my examplesid
) is auto-generated property. So when I add the record - it is always NOT expected to be set (is optional). And when you retrieve the data - the property is always set.Currently I use the same interface and this causes issues, because the code always assumes that the retrieved data for property
sid
could be null..I know that I can probably use mapper to map the results to a new interface when data is retrieved, but maybe there is more elegant solution.. (p.s.
typescript
user day 1)edit: actually, after giving it some thought I have done the following:
it works, not sure if this is how it's supposed to be handled though..