TypeScript code generator

Generates TypeScript interfaces, classes and functions for a JSDL web service.

Output dependencies:
  • GenerateServiceClass (default: false): If false, the operation functions are exported directly, otherwise a service client class is exported
  • GenerateBaseUrl (default: true)
  • GenerateInterfaces (default: true): Otherwise class generation => not implemented yet!
  • UseKnockoutJs (default: false): Parameter conversion with ko.toJSON
  • LibraryPath (default: "libs"): Directory of the jquery.d.ts and knockout.d.ts files
  • AlertExceptions (default: true): Shows an alert if there was a web service exception
  • See code generator for more options


Sample command line call:

jsdl --type TypeScript --jsdl "http://rsuter.com/Services/Jsdl/SampleService.php?operation=jsdl" --output SampleService.ts

Usage of the generated TypeScript class (using GenerateServiceClass = false, compiled as AMD module):

import service = module("SampleService");
service.sum(1, 2, (result) => {

T4 template

A sample T4 template can be found here:

Important: Change the "Build Action" of the generated .ts file to "TypeScriptCompiler"!


It is recommended to implement an access manager which sets the username / password for a service client object. The following code shows a sample access manager implemented in TypeScript:

import dataService = module("services/DataService");

export var person: dataService.Person;

export var login = function(username: string, password: string, completed: (exception: dataService.JsdlException) => void) {
	dataService.beforeSend = (xhr) => {
			"Basic " + btoa(username + ":" + password));

	dataService.getCurrentPerson((person, exception) => {
		this.person = person;

export var logout  = function() {
	dataService.beforeSend = null; 


import accessManager = module("AccessManager");

accessManager.login("foo", "bar", exception => {
	if (exception !== null)
		mt.alert("Error", exception.message);

// get the current person: 
var currentPerson = accessManager.person;

Last edited Jul 26, 2013 at 12:00 PM by rsuter, version 21


No comments yet.