locked
How to Enable IntelliSense for IndexedDB and DOM Objects RRS feed

  • Question

  • I have just started to learn how to develop a client-side web app using Visual Studio 2019 Community on a Windows 10 laptop.  The app I am exploring will use an IndexedDB for local storage.  In my initial exploration, I have run into situations where VS apparently does not know the type of IndexedDB and DOM objects and therefore IntelliSense is unable to help me discover the object's properties and methods.  I discovered that I can use "as any" as a workaround in TypeScript for the error that's triggered by an unknown property or method reference (this generates functional JS code),  and that I can alternatively explicitly type cast the object using TypeScript's bracket (<>) notation. The issue is that finding the type of certain objects is not easy.  I tried to do this by looking for the type of an "as any" object in the debugger, but that was hit and miss.

    So, is there a way to tell VS how to discover IndexedDB and DOM object types so that IntelliSense works seamlessly or, failing that, is there a way in VS to easily find the type of IndexedDB and DOM objects so that I can explicitly cast them instead of using "as any"?    If there isn't a way to do either of these using VS, can you at least point me to documentation of the IndexedDB and Html DOM objects that shows the object type that TS will recognize?  I have included a few of the examples of where I have and haven't been successful in explicitly type casting.

    Thanks.  Steve 

    // Successful DOM casting
    var colIndex = (<HTMLTableDataCellElement>elem).cellIndex;
    var rowIndex = (<HTMLTableRowElement>elem.parentNode).rowIndex;
    
    // Unsuccessful DOM casting.  Statement 1 triggers an error.
    // I can't find what object type getElementById returns
    let stringKey = (<HTMLElement>document.getElementById("recordNumber")).value;
    let stringKey = (document.getElementById("recordNumber") as any).value;
    
    // Successful IndexedDB casting
    dbReq.onsuccess = function (event) { myDatabase = (<IDBOpenDBRequest>event.target).result; let x = 1; }
    //dbReq.onsuccess = function (event) { myDatabase = (event.target as any).result; let x = 1; }

    Monday, May 25, 2020 1:13 PM

Answers

  • Hi Steve,

    Welcome to MSDN forum.

    >> is there a way in VS to easily find the type of IndexedDB and DOM objects so that I can explicitly cast them instead of using "as any"?

    ## Based on my testing, I don’t find good way to enable IntelliSense for IndexedDB and DOM objects.

    >> If there isn't a way to do either of these using VS, can you at least point me to documentation of the IndexedDB and Html DOM objects that shows the object type that TS will recognize? 

    ## For your requirement, I recommend you redirect to the Stack Overflow tagged typescript or indexeddb for a more professional help.

    Thanks for your understanding and have a nice day.

    Best Regards,

    Anna

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by Cincy Steve Tuesday, May 26, 2020 12:21 PM
    Tuesday, May 26, 2020 9:58 AM

All replies

  • Hi Steve,

    Welcome to MSDN forum.

    >> is there a way in VS to easily find the type of IndexedDB and DOM objects so that I can explicitly cast them instead of using "as any"?

    ## Based on my testing, I don’t find good way to enable IntelliSense for IndexedDB and DOM objects.

    >> If there isn't a way to do either of these using VS, can you at least point me to documentation of the IndexedDB and Html DOM objects that shows the object type that TS will recognize? 

    ## For your requirement, I recommend you redirect to the Stack Overflow tagged typescript or indexeddb for a more professional help.

    Thanks for your understanding and have a nice day.

    Best Regards,

    Anna

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by Cincy Steve Tuesday, May 26, 2020 12:21 PM
    Tuesday, May 26, 2020 9:58 AM
  • Thanks, Anna, for the quick reply.  I will post the question to Stack Overflow as you suggest.
    Tuesday, May 26, 2020 12:21 PM