Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using TypeScript in cshtml files

I'm wondering is there any way to use TypeScript on Razor cshtml files?

For example, something like this

<script language="text/typescript"> /// typescript goes here </script> 
like image 846
Tom Kris Avatar asked Oct 02 '12 17:10

Tom Kris


People also ask

Can I use TypeScript in ASP net MVC?

In this article we were able to run TypeScript in our ASP.NET MVC project. I would like to point that this article contained a very basic example of TypeScript and obviously you would want to use TypeScript for what it really was created for (Classes, interfaces, dependency injections, etc…)

Can I use TypeScript in JavaScript?

You can use thousands of existing JavaScript libraries in your TypeScript project. Type definition files allow you to enjoy the type-checking and autocomplete features in libraries that were written in JavaScript. These files make you more productive in writing code.

Can we run TypeScript in browser?

To run TypeScript in a browser, it needs to be transpiled into JavaScript with the TypeScript compiler (tsc). In this case, tsc creates a new . js file based on the . ts code, which you can use any way you could use a JavaScript file.

How to write TypeScript code in typescripr?

Create a typescript file for writing the TypeScript code Create a new tsconfig.json file also know as TypeScripr configuration file. We have to create it in the root folder. You have to create a file like this in the TsConfig folder or whatever folder name you have to give. Open the tsconfig.json file and write the following code in it.

What is the difference between typescript and cshtml files?

TypeScript transpiler only checks and transpiles files that only contain : Javascript with some syntaxique sugar code added by TypeScript (static typing, generic class etc...) CSHTML files are basically created to contain Razor/C# code and of course HTML/JavaScript/CSS.

How to transpile TypeScript into JavaScript?

Transpile TypeScript into JavaScript #. Step 1: Create a simple TS file #. Open VS Code on an empty folder and create a helloworld.ts file, place the following code in that file... Step 2: Run the TypeScript build #. Step 3: Make the TypeScript Build the default #. Step 4: Reviewing build issues #. ...

How to integrate typescript in ASP NET MVC 5?

Create a new ASP.NET MVC 5 application or take any existing application in which you have to integrate the TypeScript. Create a typescript file for writing the TypeScript code Create a new tsconfig.json file also know as TypeScripr configuration file.


1 Answers

It's possible. I have developed TypeScript Compile - an automatic compiler of TypeScript to JavaScript on the fly. Have a try!

like image 117
niutech Avatar answered Sep 21 '22 13:09

niutech