locked
(TS) Property 'X' does not exist on Type 'Y' when moved from index.cshtml to a TS file RRS feed

  • Question

  • I am new to web app development, and am therefore feeling my way through it all based on a lot of reading and test apps.  I am running Visual Studio 2019 Community on a Windows 10 laptop, trying to create an Asp.NET Core MVC app. 

    I added some <script> code to the index.cshtml file and invoked it from the html code.  That worked as expected.  But when I moved that same code (absent the <script> tags) to a TypeScript file I added to a "scripts" folder in the project, references to the event.target.result and .errorCode properties as well as to the getElementById('x').value property were flagged as "does not exist".   

    Any idea what I am missing.

    Thanks.  Steve

    Tuesday, May 19, 2020 8:45 PM

Answers

  • Hi Steve,

    Welcome to MSDN forum.

    In order to investigate this issue further, can you share me the code in the index.cshtml file? You can have a look at the similar issue and hope it helps.

    BTW, since our forum focus on Visual Studio IDE related issues, this issue is more about code development. You can also report it to the ASP.NET Core forum. Thanks for your understanding.

    Hoping everything goes well.

    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 Wednesday, May 20, 2020 2:03 PM
    Wednesday, May 20, 2020 3:27 AM
  • Hi Steve,

    Since the principle of our forum is that a post only discusses one issue, if you have other issue about Visual Studio IDE, please restart a new thread for a better support. Thanks for your understanding.

    Have a nice day.

    Sincerely,

    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


    Monday, May 25, 2020 10:00 AM

All replies

  • Hi Steve,

    Welcome to MSDN forum.

    In order to investigate this issue further, can you share me the code in the index.cshtml file? You can have a look at the similar issue and hope it helps.

    BTW, since our forum focus on Visual Studio IDE related issues, this issue is more about code development. You can also report it to the ASP.NET Core forum. Thanks for your understanding.

    Hoping everything goes well.

    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 Wednesday, May 20, 2020 2:03 PM
    Wednesday, May 20, 2020 3:27 AM
  • Anna -

    Thanks for responding.  The "as any" suggestion in the similar issue, while being a brute force hack, solved the problem.  

    Also, I appreciate your observation about the forum I should have used.  I wondered when selecting this one if it was right.  I will certainly start to use the ASP.NET Core one.

    Steve 


    • Edited by Cincy Steve Wednesday, May 20, 2020 3:14 PM
    Wednesday, May 20, 2020 2:03 PM
  • Hi Steve,

    Good to hear it is working now.

    Starting to study the ASP.NET Core, you could see the following document and hope it helps:

    https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-3.1

    If there is anything else we can do for you, please feel free to post in this forum.

    Have a nice day.

    Sincerely,

    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

    Friday, May 22, 2020 9:50 AM
  • Anna -

    Thanks for the suggested documentation.  I had started into it when I ran into my original question and was trying out some of what the documentation describes.  I have a clarification to my original question.  Please let me know if I should submit it as a new question.  This one does seem related to the VS IDE.

    I'm thinking that my original problem is a reflection of Intellisense not working in every case where I hope it would, at least if there is some way to explicitly type object references.  In particular, it's not working:

    1. In my TypeScript code when I reference certain properties of DOM elements.  For example, I need "as any" when trying to reference the cellIndex property of the document.activeElement when that element is a <td>.

    2. When I display DOM elements in the Immediate Window while debugging at a break point;

    3. In my TypeScript code when I reference IndexedDB objects.  For example, on nested properties of the "event" object returned via various onYYY events.  See the sample code below from my TypeScript file.  The code requires "as any" even when the contained property does exist. 

    Is there a way to get Intellisense to work in these circumstances?   

    Thanks.  Steve

    var dbReq = indexedDB.open( databaseName, 1 );
    dbReq.onupgradeneeded = function ( event ) 
        {
            myDatabase = (event.target as any).result;
            // more code...
        }
        dbReq.onsuccess = function (event) { myDatabase = (event.target as any).result;}
        dbReq.onerror = function ( event ) { alert( 'error opening database ' + (event.target as any).errorCode ); }










    Sunday, May 24, 2020 4:43 PM
  • Hi Steve,

    Since the principle of our forum is that a post only discusses one issue, if you have other issue about Visual Studio IDE, please restart a new thread for a better support. Thanks for your understanding.

    Have a nice day.

    Sincerely,

    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


    Monday, May 25, 2020 10:00 AM