Skip to content

Limitations or Constraints of Generated TypeScript Codes

fonlow edited this page Jun 1, 2017 · 1 revision

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);
        }
Clone this wiki locally