
Migrating JavaScript to TypeScript in ASP.NET MVC Projects
*By Sean Erick C. Ramones, Vue SME | JavaScript/TypScript SME*
Sean Erick C. Ramones
Introduction Many legacy ASP.NET MVC applications rely on JavaScript for client-side behavior. While JavaScript is flexible, it lacks the static typing and development-time tooling that modern TypeScript provides. Migrating to TypeScript can significantly improve code maintainability, reduce bugs, and enhance developer productivity. This report explores how to incrementally adopt TypeScript in an existing ASP.NET MVC project, including recommended practices and tooling.
Getting Started
- Install TypeScript
- Install globally or as a dev dependency:
npm install -D typescript
- Install globally or as a dev dependency:
- Create a
tsconfig.json{ "compilerOptions": { "target": "es6", "module": "commonjs", "outDir": "wwwroot/js", "rootDir": "Scripts/ts", "strict": true, "esModuleInterop": true } } - Directory Structure Suggestion
Scripts/js/→ legacy JavaScript filesScripts/ts/→ new TypeScript fileswwwroot/js/→ compiled JavaScript output
Integrating with ASP.NET MVC Views
- Compile
.tsfiles to.jsand reference them in your Razor views just like normal JavaScript files. - Use bundling/minification tools such as Bundler & Minifier or integrate with Webpack (see below).
Incremental Migration Strategy
- Start with TypeScript-Compatible JavaScript
- Rename
.jsfiles to.tsand fix immediate type issues. - Use
@ts-ignorewhere absolutely necessary to suppress errors temporarily.
- Rename
- Add Types Gradually
- Leverage
anyfor legacy code where typing is unclear. - Introduce
interfaces andtypes as you refactor or touch code.
- Leverage
- Use Declaration Files
- Install type definitions for third-party libraries:
npm install -D @types/jquery @types/bootstrap
- Install type definitions for third-party libraries:
Optional: Webpack Integration For better asset bundling and live reload:
- Install Webpack and Loaders
npm install -D webpack webpack-cli ts-loader - Example
webpack.config.jsmodule.exports = { entry: './Scripts/ts/app.ts', module: { rules: [ { test: /\.ts$/, use: 'ts-loader', exclude: /node_modules/ } ] }, resolve: { extensions: ['.ts', '.js'] }, output: { filename: 'bundle.js', path: path.resolve(__dirname, 'wwwroot/js') } };
Challenges & Tips
- Legacy jQuery Usage: Use type declarations and gradually refactor jQuery-heavy code.
- Global Variables: Declare global types or refactor to modules.
- Razor View Conflicts: Avoid mixing complex inline scripts with TypeScript logic.
Conclusion Migrating from JavaScript to TypeScript in ASP.NET MVC projects brings substantial long-term benefits. With careful planning, it can be done incrementally without disrupting existing functionality. Leveraging modern build tools like Webpack can further streamline the process and improve maintainability. This approach ensures your frontend stack evolves alongside your backend, enabling a modern and scalable web application architecture.
Notes: This is also a key part in the endeavor of migrating the Voky project, wherein we try to move from JQuery and pure Javascript - into a modular type-safe scripts with VueJS to incrementally replace old JS widgets.
A Tribute to Asa Bain: Thank You for Everything
On October 24, 2025, we said goodbye to one of the most talented and dedicated individuals our team has ever had the privilege of working with—Asa Bain. After years of outstanding contributions to Mil...
Modernizing Classic ASP.NET MVC with Vue.js
*By Sean Erick C. Ramones, Vue SME | JavaScript/TypeScript SME*