Nested namespace

TypeScript also allows us to create nested encapsulation by adding a namespace inside another namespace. The nested namespace to be exposed outside should also be prefixed with the export keyword. The following is an example of how we can use nested namespaces:

namespace WebServiceResponse{  let url: string;  export namespace ServiceResponse{    export class WebResponse{      getResponse(){        return "Success";      }      sendResponse(){        return "200 OK";      }    }  }   let localResponse = new ServiceResponse.WebResponse();  localResponse.getResponse();  localResponse.sendResponse();}let response = new WebServiceResponse.ServiceResponse.WebResponse();response.getResponse();response.sendResponse();

As you can see in the example, we have introduced a nested ...

Get TypeScript 2.x By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.