Tuesday, July 31, 2018

Rest Parameters in TypeScript

In TypeScript, Rest Parameters are often used in functions to specify the parameters when the number of parameters is unknown.

Let’s go by a sample scenario. Imagine we need to have a method which will return us the full address (nicely separated by “,”) when different parts of the address are supplied. Some addresses have Address Line 1, Address Line 2 etc., and for some, there is no Address Line 2, likewise.

In this case, there is no fixed number of parameters. To cater such a requirement, we can have the following function with Rest Parameters.
function buildAddress(...addressLines) {
    return addressLines.join(", ");
};
Here the Rest Parameter is the addressLines, we are using JavaScript split operator (ellipsis) to specify that.

With TypeScript it’s always better to be explicit. You can specify the type of the Rest Parameters as well. And note, it should always be an array type as behind the scene it really is an array.
function buildAddress(...addressLines: string[]) {
    return addressLines.join(", ");
};
We can call the function like below.
console.log(buildAddress("111-2222", "Bing Street", "Springfield Gardens", "NY", "33333"));
// 111-2222, Bing Street, Springfield Gardens, NY, 33333

console.log(buildAddress("111-2222", "Springfield Gardens", "NY", "33333"));
// 111-2222, Springfield Gardens, NY, 33333
And you can even not pass anything at all.
console.log(buildAddress());
Isn’t it nice!

Happy Coding.

Regards,
Jaliya

Sunday, July 29, 2018

Visual C# Technical Guru - June 2018

Another month as a judge in Microsoft TechNet Guru Awards under Visual C# category. The TechNet Guru Awards celebrate the technical articles on Microsoft TechNet.

image
Visual C# Technical Guru - June 2018
Happy Coding.

Regards,
Jaliya

Sunday, July 1, 2018

Received Microsoft MVP Award in Visual Studio and Development Technologies

I am humbled, pleased and honored to receive the precious Microsoft Most Valuable Professional (MVP) Award for the fifth consecutive year. In the last couple of years received the award on 1st of January, but this time it's on 1st of July due to changes in Microsoft MVP Program. The expertise category which I received the award for is same as the last year, that is Visual Studio and Development Technologies. In the first two years, I have been awarded MVP for Visual C# and then .NET.

As always looking forward to another great year on top of Microsoft Development Stack.
MVPLogo_thumb[2]
Microsoft Most Valuable Professional (MVP)
Thank you Microsoft for your appreciation and Thank you Wellington PereraFiqri IsmailChaminda Chandrasekara and everyone for your continuous support and guidance.

Happy Coding.

Regards,
Jaliya