Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken IndexedDB event typings in 3.1.5 #28293

Open
dpogue opened this issue Nov 1, 2018 · 3 comments
Open

Broken IndexedDB event typings in 3.1.5 #28293

dpogue opened this issue Nov 1, 2018 · 3 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Milestone

Comments

@dpogue
Copy link

dpogue commented Nov 1, 2018

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;
}
@weswigham weswigham added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Nov 2, 2018
@weswigham
Copy link
Member

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@sandersn
Copy link
Member

Following on to @weswigham’s comment, this is now easily fixed as an extension to microsoft/TypeScript-DOM-lib-generator#707; ProgressEvent now has a type parameter that controls the type of target, so it’s just a matter of passing the type in from the subclass declaration.

@tonitrnel
Copy link

It can be write like this

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants