Introduction
In this article, you will learn about implementing basic TypeScript examples on SharePoint, using classes and variables, using Visual Studio.
In my previous article, you have learned TypeScript basics and prerequisites to be available on Visual Studio for SharePoint TypeScript programming.
In my other article, I have explained about implementing TypeScript basic examples in SharePoint Visual Studio SharePoint Project.
Here, we will learn how to retrieve SharePoint site details, using class, constructor, function and variables with the help of TypeScript. In this way, the programmers can develop the components in an object oriented programming language. With the help of ECMAScript approach in TypeScript, the developers can build Applications in object oriented class based approach.
Defining Class
Let us define a class with the members. The members can be variables, constructors and functions. The class name in the example is GetSiteInfo. It has four members, which are as follows.
- Property called context, which is of type 'SP.ClientContext'
- Property called web, which is of type 'SP.Web'
- Constructor is used to set the default values. In this case, the client context and Web objects are set.
- Function to get necessary information.
The class is instantiated with the help of the object. During instantiation,
- The properties will be loaded.
- The constructor will set the necessary data for the properties.
In the constructor, the context object and Web object needs to be set, using the respective methods.
In the function, define the local variables for context and Web. Using the local context variable, the Web object is loaded and the query needs to be executed. The code will be very similar to ECMAScript programming. You can also write your custom logic to get the necessary information.

Humayun Kabir MamunPosted Nov 13, 2016, 1:59 AM
Nice work with SharePoint...