typicode / lowdb

Simple and fast JSON database
MIT License
21.35k stars 918 forks source link

How to use with typescript when using lodash? #521

Closed luluhoc closed 2 years ago

luluhoc commented 2 years ago

When i'm trying to use with lodash I'm getting

Property 'chain' does not exist on type 'Low<IJobs>'.
ste163 commented 2 years ago

One fix is by making a new interface that extends the Low class to include the chain.

interface NewLowDb extends LowSync<MyDatabase> {
  chain: ObjectChain<MyDatabase>;  // Needed to include the chain function
}

Then wherever you're setting up your database, you use the new interface.

typicode commented 2 years ago

Thanks @ste163

I've updated docs how to use lodash and TypeScript together. I haven't tested it thoroughly but it should work.