none
Can C sharp class uses a Type Script instance/object RRS feed

  • Question

  • Hi,

    I wonder if anyone has been trying to create an instance of a Type script class in a C sharp class. I am unable to create it it errors and cannot find it.

    I did explore and found that its not straight forward but lot of examples were converting complete code, in my instance I want to create an object -Type Script class in my C sharp class.

    Could anyone help me understand if that is possible ?

    Thanks,

    Monday, January 28, 2019 11:42 AM

Answers

  • You cannot call TypeScript classes from C# (at least directly that I'm aware of). TypeScript is designed to run in a sandbox environment like the browser or an NPM server. Perhaps you are misusing the technology. If you are running server-side code you'd use C#. If you need to write client side code then you'd use TypeScript in lieu of JavaScript. There is nothing in TS that you cannot already do in C#. TS is really designed to replace JS in a type-safe manner. If you wouldn't use JS to solve a problem then TS isn't the correct choice either.

    Many apps are supporting writing "extensions" via TypeScript but in all cases I've seen it is either being hosted via the browser or run via NPM. There isn't a case where you'd call TS from C#.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Aou16 Tuesday, January 29, 2019 12:45 PM
    Monday, January 28, 2019 5:02 PM
    Moderator

All replies

  • Hello, 

    If you have TypeScript compiler for .Net - you can do it. 


    Sincerely, Highly skilled coding monkey.

    Monday, January 28, 2019 12:09 PM
  • Hi,

    Thank you for the reply. I am using Visual Studio 2017 and its a Serenity project. I am able to compile my project it is a combination of Typescript , C# and Javascript files. However in one of my .cs file when I try to create an instance of a .ts class it is unable to find the class. I concluded this as within the same namespace I tried to find the .cs in a .cs it is able to find but not a .ts class.

    Could you elaborate your reply to resolve my issue.

    Thanks you.

    Monday, January 28, 2019 12:41 PM
  • You cannot call TypeScript classes from C# (at least directly that I'm aware of). TypeScript is designed to run in a sandbox environment like the browser or an NPM server. Perhaps you are misusing the technology. If you are running server-side code you'd use C#. If you need to write client side code then you'd use TypeScript in lieu of JavaScript. There is nothing in TS that you cannot already do in C#. TS is really designed to replace JS in a type-safe manner. If you wouldn't use JS to solve a problem then TS isn't the correct choice either.

    Many apps are supporting writing "extensions" via TypeScript but in all cases I've seen it is either being hosted via the browser or run via NPM. There isn't a case where you'd call TS from C#.


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Aou16 Tuesday, January 29, 2019 12:45 PM
    Monday, January 28, 2019 5:02 PM
    Moderator
  • Thank you so much Michael, your information is very helpful for me. I did not know this background and was struggling to use the Typescript method in C#.

    Regarding my issue: I found the C# relevant function to resolve my problem.

    Thanks you so much once again.

    Any more information that you think that helps me please do share.

    Thanks

    Aou

    Tuesday, January 29, 2019 12:45 PM