Home > DeveloperSection > Forums > What type to give a JSON object
Manoj Bhatt
Manoj Bhatt

Total Post:153

Posted on    January-22-2014 11:51 PM

 C# C# 

 1 Reply(s)
 680  View(s)
Rate this:

I have the following form

 using (Ajax.BeginRouteForm(


                new AjaxOptions


                    HttpMethod = "POST",

                    OnFailure = "OnFailure",

                    OnSuccess = "OnSuccess"





I implement the OnSuccess function in a TypeScript file. I am trying to make this function more TypeScripty. At the moment I have this

function OnSuccess(data: what type goes here?) {


// use data.SomeValue here



Question is what type shall I say data is such that I can still somehow use data.SomeValue?

Pravesh Singh

Total Post:411

Posted on    January-23-2014 12:57 AM

Hi Manoj,

The best way is with an interface, because you make an explicit assertion of the structure of the object returned and communicate very clearly what the callback expects.

export interface IOnSuccessArgs {

    propertyA: string;

    propertyB: number;


function OnSuccess(data: IOnSuccessArgs): void {

   // ... data has propertyA and propertyB


Don't want to miss updates? Please click the below button!

Follow MindStick