microsoft / microsoft/TypeScript

Broken IndexedDB event typings in 3.1.5

Open
#28,293 4 comments 33 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: lib.d.ts
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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 https://github.com/Microsoft/TypeScript/issues/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;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TypeScript 3.1.5 DOM typings involved in the IndexedDB event callbacks, using the Playground link to reproduce the error. Read related issue #25547 to understand the preceding changes, then verify that the sample recognizes evt.target.result as an IDBDatabase without a cast.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.