DEV Community

Cover image for IndexedDB in TypeScript
Daniele Falchetti
Daniele Falchetti

Posted on β€’ Edited on β€’ Originally published at aprograma.com

15 3 3 3 3

IndexedDB in TypeScript

TypeScript's configuration of IndexedDB


A quick description from Javascript.info on what IndexedDB is.

IndexedDB is a database that is built into a browser, much more powerful than localStorage.

  • Stores almost any kind of values by keys, multiple key types.
  • Supports transactions for reliability.
  • Supports key range queries, indexes.
  • Can store much bigger volumes of data than localStorage.

That power is usually excessive for traditional client-server apps. IndexedDB is intended for offline apps, to be combined with ServiceWorkers and other technologies.

As confirmed by virtually everyone, the API of IndexdDB is difficult to manage for most people, although in TypeScript it could be worse.

For this, I created a repository with a standard IndexedDB configuration in TypeScript. I hope to help someone.

The repository 🫑

Top comments (0)

11 Tips That Make You a Better Typescript Programmer

typescript

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields

...

Read the whole post now!