This project has moved. For the latest updates, please go here.

Since Javascript is inherently a very dynamic language, the support for function overloading in TypeScript is fairly limited. Thus the one to one mapping between controller functions and TypeScript functions will resulting in overloading functions which Javascript doesn't like. The measurement in Strongly Typed Client API Generators is to rename overloading functions with the parameter signature.

    [RoutePrefix("api/hello")]
    public class HelloController : ApiController
    {
        // GET: api/hello
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET: api/hello/5
        public string Get(int id)
        {
            return "value"+id;
        }

The generated TypeScript codes will be:

        Get(callback: (data : Array<string>) => any){
            this.httpClient.get('api/Values', callback, this.error, this.statusCode);
        }

        GetByIdAndName(id: number, name: string, callback: (data : string) => any){
            this.httpClient.get(encodeURI('api/Values/'+id+'?name='+name), callback, this.error, this.statusCode);
        }

Last edited Nov 2, 2015 at 9:59 PM by zijianhuang, version 2