fix: tsc error

This commit is contained in:
Adhiraj Singh
2023-03-18 17:40:43 +05:30
parent bb27e58c3e
commit 6bced98128

View File

@@ -97,15 +97,21 @@ export const addTransactionCapability = (
* prefetches some data and stores in memory,
* useful if these data points will be used together often
* */
const prefetch = async(type: keyof SignalDataTypeMap, ids: string[]) => {
const prefetch = async<T extends keyof SignalDataTypeMap>(type: T, ids: string[]) => {
const dict = transactionCache[type]
const idsRequiringFetch = dict ? ids.filter(item => !(item in dict)) : ids
const idsRequiringFetch = dict
? ids.filter(item => typeof dict[item] !== 'undefined')
: ids
// only fetch if there are any items to fetch
if(idsRequiringFetch.length) {
dbQueriesInTransaction += 1
const result = await state.get(type, idsRequiringFetch)
transactionCache[type] = Object.assign(transactionCache[type] || { }, result)
transactionCache[type] ||= {}
transactionCache[type] = Object.assign(
transactionCache[type]!,
result
)
}
}