Skip to content

Broken IndexedDB event typings in 3.1.5 #28293

Open
@dpogue

Description

@dpogue

TypeScript Version: 3.1.5

Search Terms:
indexedDB

Code

let dbreq = indexedDB.open('test', 1);

dbreq.onsuccess = function (evt) {
    let database = evt.target.result;
}

Expected behavior:
evt.target.result should be an IDBDatabase

Actual behavior:
TS2339: Property 'result' does not exist on type 'EventTarget'.

Playground Link:
http://www.typescriptlang.org/play/index.html#src=let%20dbreq%20%3D%20indexedDB.open('test'%2C%201)%3B%0D%0A%0D%0Adbreq.onsuccess%20%3D%20function%20(evt)%20%7B%0D%0A%20%20%20%20let%20database%20%3D%20evt.target.result%3B%0D%0A%7D

Related Issues:
This is caused by the updates resulting from #25547

It works if you add a cast:

let dbreq = indexedDB.open('test', 1);

dbreq.onsuccess = function (evt) {
    let database = (evt.target as IDBOpenDBRequest).result;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions