This repository has been archived by the owner on May 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Examples
cskeppstedt edited this page Nov 21, 2012
·
2 revisions
C# classes:
[TypeScriptInterface]
public class MyModel
{
public int Number { get; set; }
public string Name { get; set; }
public ReferencedModel Ref { get; set; }
}
[TypeScriptInterface]
public class ReferencedModel
{
public double Fraction { get; set; }
public int[] Digits { get; set; }
}
Resulting T4TS.d.ts:
module T4TS {
export interface MyModel {
Number: number;
Name: string;
Ref: ReferencedModel;
}
export interface ReferencedModel {
Fraction: number;
Digits: number[];
}
}
This interface can now be used in your TypeScript files:
/// <reference path="T4TS.d.ts" />
class Test {
constructor () {
// Make an AJAX post and get some data from the server.
// In the callback, you can specify that the data is of a certain type:
$.post('./example', {}, (data: T4TS.MyModel) => {
// Intellisense support for the properties:
alert(data.Number.toString());
alert(data.Ref.Digits[0].toString());
});
}
}