Types May Finally Be Coming to JavaScript

With the promotion of Type Annotations to Proposal Level 1 Stage, JavaScript is one step closer to being a more strongly typed language. Let's dive into what the changes will mean for JavaScript.

Types in JavaScript

JavaScript is dynamically typed. That means that it figures out the type of something by where it appears. For example:

Some Helpful Extensions When Dealing With Types in .NET

If you are writing reusable code, chances are high that you will write quite some code that deals with types, generics, and interfaces. Over the years, the collection of my helper extensions for that have grown. As some of my upcoming posts use them, I share them (also) for future reference.

1. Check if a Type Is Deriving From Another Type

Deriving types is a common practice. To some extent, you can use pattern matching. Sometimes, that isn't enough, though (especially if you have a multi-level derivation path). This is when I use one of these two extensions:

Typing Resistance

I assure you, this is a post about programming, it’ll just take a few paragraphs to get there.

There’s a biological mechanism known as resistance, and it plays out in many different systems. For example, as you habitually drink more alcohol, you gain a tolerance, which prevents you from getting drunk as easily. This can be called alcohol resistance. When you habitually run high levels of insulin, your body becomes less sensitive to insulin, making you insulin resistant. When you go into a loud room, your ears adjust down the sound, making you noise resistant. And when you change enough dirty diapers, you become smell resistant.

Generic Extension Method to Map Objects From One Type to Another

Let me start with one scenario. Just imagine we have an object which has lots of public properties and we need to use only some properties of it for the user profile method. For example, we have a class Teacher_Interview and another class named Teacher_College.

Public class Teacher_Interview  
{  
    Public int UID {get; set;}  
    Public string Name {get; set;}  
    Public string Email {get; set;}  
    Public string Subject {get; set;}  
}  
  
Public class Teacher_College  
{  
    Public int TID {get; set;}  
    Public string Name {get; set;}  
    Public string Email {get; set;}  
}  

Here, we have written both the classes. As we can see, we have a Teacher_Interview class that contains its public properties. Now, we need to use the Teacher_College class object and want the same values from the Teacher_Interview class object.