Saeid Doroudi Saeid Doroudi - 9 months ago 44
TypeScript Question

Convert Javascript (angular app) to Typescript

I want to implement pluginable angular app and i use this tutorial for solve problem and this tutorial uses RequireJs for load scripts in correct order

I want to convert this project to type script and i don't know how to use RequireJs in Typescript

for example this is my App.js Code :

define(['require', 'angular', 'underscore', 'src/modules/definitionsLoader.js', 'ngMaterial', 'ui.router', 'ngCookies', 'ngFileUpload' , 'src/controllers/controllers.js'],
function (require, angular, _ , definitionsLoader) {

require(definitionsLoader.scriptsToLoad, function () {
return initializeApp(angular);

function initializeApp(angular) {
var application = angular.module('app', definitionsLoader.modulesToLoad)
'$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.when('', '/home');
.state('home', {
url: '/home',
templateUrl: 'src/views/dashboard.html',
controller: function() {

controllerAs: 'ctrl'

var states = definitionsLoader.statesToConfigure;
for (var i = 0; i < states.length; i++) {

var state = states[i];
$stateProvider.state(state.stateName, { url: state.url, controllerAs:'vm' , abstract: state.abstract, templateUrl: state.templateUrl, controller: state.controller });
}]).run(['$rootScope', function ($rootScope) {
$rootScope.modules = definitionsLoader.modules;

angular.bootstrap(document, ['app']);


Since valid JavaScript code is also valid TypeScript code, your snippet "is already" TypeScript. If you also want intellisense and all the good stuff that comes with TypeScript you have to use a .d.ts file. You can find the requirejs.d.ts here. For an easy install I would recommend typings.