1

I'm reading the documentation through mdn, but the interface which is in onupgradeneeded, doesn't return the result and with that I can't create the objects in the database.

const request = window.indexedDB.open("MyTestDatabase", 3);

request.onupgradeneeded = (event) => {
    const db = event.target?.result;
    const objectStore = db.createObjectStore("name", { keyPath: "myKey" });
};

ERROR:

Property 'result' does not exist on type 'EventTarget'.ts(2339)

SIGNATURE:

/** Also inherits methods from its parents IDBRequest and EventTarget. */
interface IDBOpenDBRequest extends IDBRequest<IDBDatabase> {
    onblocked: ((this: IDBOpenDBRequest, ev: IDBVersionChangeEvent) => any) | null;
    onupgradeneeded: ((this: IDBOpenDBRequest, ev: IDBVersionChangeEvent) => any) | null;
    addEventListener<K extends keyof IDBOpenDBRequestEventMap>(type: K, listener: (this: IDBOpenDBRequest, ev: IDBOpenDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
    removeEventListener<K extends keyof IDBOpenDBRequestEventMap>(type: K, listener: (this: IDBOpenDBRequest, ev: IDBOpenDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
    removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
THIAGO DE BONIS
  • 760
  • 7
  • 22
  • 1
    My bad I was a little quick on the trigger. Changing to `currentTarget` does not actually fix this. Use `request.result` instead and it should fix. – Jared Smith Dec 12 '22 at 21:20

0 Answers0