What is TypeScript and how does it work with CRM 2011/2013

I prodded CRM MVP Dave Berry with a twitter stick, berating him to start blogging again, this is dangerous because he is a CRM Super Hero

You should read his CRM MVP Q&A, it’s very funny and interesting

Th reason I was prompting him because I was reminded of his great blog posts because I was reading a blog post from Guido Preite who wrote an excellent blog entry –  Entity.GetAttributeValue<T> and ActivityParty, This is a great blog post from Guido and I would recommend all CRM Developers to read it (and subscribe to his blog).

In the blog he links to a Dave Berry blog post explaining Entity.GetAttributeValue.

Entity.GetAttributeValue Explained

This prompted me to tweet Dave Berry and he said he was doing some work on TypeScript and CRM.

What is TypeScript

Lets start with Wiki Definition


TypeScript is a free and open source programming language developed and maintained byMicrosoft. It is a strict superset of JavaScript, and adds optional static typing and class-basedobject-oriented programming to the language. Anders Hejlsberg, lead architect of C# and creator of Delphi and Turbo Pascal, has worked on the development of TypeScript.[1][2][3][4]

TypeScript is designed for development of large applications and transcompiles to JavaScript.[5]As TypeScript is a superset of JavaScript, any existing JavaScript programs are also valid TypeScript programs.


Stackoverflow has a good discussion


Typescript is a superset of Javascript which primarily provides static typing, classes and interfaces. One of the big benefits is to enable IDEs to provide a richer environment for spotting common errors as you type the code.

It’s still early days, but to get an idea of what I mean, watch Microsoft’s introductory video on the language.

For a large Javascript project, adopting Typescript might result in more robust software, while still being deployable where a regular javascript application would run.

It is open source, but you only get the clever Intellisense as you type if you use Microsoft’s Visual Studio (also noted in blog post from Miguel de Icaza).


Typescript home


This site has a bunch of samples, handbook and tutorials and is probably a good place to start.

Good articles on TypeScript

Some great resources for learning type script


 TypeScript: First Impressions

Enhance Your JavaScript Investment with TypeScript

What is TypeScript

TypeScript: JavaScript Development at Application Scale

7 months


Hosk Thoughts on TypeScript

I will add I haven’t used TypeScript yet, so I’m just basing my thoughts on what I have read, whilst writing this article.  If you do want to get started using TypeScript with CRM, Dave’s article TypeScript, CRM 2011, and You is probably the best place to start.

As a Java developer and then C# I have often found JavaScript and it’s dynamic types confusing and dangerous.  It does have advantages like Using Dynamic Javascript.  Strong typing

The biggest problem I have is Javascript makes it hard to create classes and structure the code in logical and well thought out design.  The flip side of this it’s easy and tempting to right quick messy Javascript code which is a pain to debug and maintain later.  Javascript doesn’t offer much to the Developer with intellisense or code checking.  This means I can often publish code with syntax errors in it!!!

The first interesting point about TypeScript is it compiles the code to JavaScript, so the end product of your CRM development will be the same e.g. a javascript file.  You can almost think of it as the difference between writing early bound and late bound code.  The advantages of writing early bound plugin code, is the plugin code uses the entity classes and fields.  Early bound code has these advantages

  • Easy to read and understand
  • removes syntax errors
  • Casting and type errors are found at compile time (and not runtime by the customer)

TypeScript in my view is trying to do the same kind of standards and advantages to the JavaScript code as early bound code does to plugins.

One of the main advantages (in my opinion) is TypeScript makes it easy to create types, modules and interfaces in your code, which means the code will be more like the strong typing (C#) code.  This should make it easier for developers to create well structured code and less excuses for Developer to create hacky, messy Javascript.

Auto Complete/Intellisense improvements

Reading the http://www.typescriptlang.org/ page, another benefit is with strong typing (read this wiki article about strong and weak typing) is you can get visual studio tools/development tools to help with best practices, static checking and code re-factoring of the TypeScript code.  I understand this to mean it’s like writing plugins using early bound code, with Visual studio helping you easily select fields (defined in your entities file) and refactoring and check your code for best practices with tools like ReSharper and FXCop

The benefit of visual studio helping autocomplete all the Out of the box Javascript functions is probably worth it alone




TypeScript was created by Microsoft

Microsoft created TypeScript to help .NET developers create similar code in JavaScript as they create in .NET.


CRM and TypeScript

There isn’t currently lots of resources or examples of TypeScript and CRM, I’m not suprised by this because until Dave mentioned I hadn’t really heard much about it.

Before you start creating any TypeScript I think I would start with the article written by Dave Berry

TypeScript, CRM 2011, and You

The blog post was from May 2013, so it will be a bit out of date (I’m guessing) but Dave has put these advantages of learning TypeScript

  • Types!  (If that wasn’t the first thing on this list, I should be soundly questioned.)
  • Compiles to JavaScript by basically removing itself from the code, and applying some cohesive closure structures to the results.  (This is why all valid JavaScript is valid TypeScript.)
  • C#’s interface and inheritance model!  (Multiple inheritance isn’t supported, but multiple interfaces are.  My C++ days are calling, and I let it go to voicemail.  I’m ok with this model.)
  • Multiple method signatures!  (This doesn’t apply anything on the “compile” to JavaScript—yet—but makes the IDE experience nicer.)
  • Generics!  (…coming in TypeScript 0.9)


CRM 2013

There is a good CRM 2013 blog post (split in 2) on TypeScript, which is simple and straight forward and a great place to start learning to use TypeScript

TypeScript and Dynamics CRM 2013 – Part 1

TypeScript and Dynamics CRM 2013 – Part 2

The CRM2013 definition file is on GitHub (https://github.com/sduck/Crm2013TypeScript)


CRM 2011

There are three blog posts I found on CRM 2011 and TypeScript

Using TypeScript for CRM 2011


TypeScript, CRM 2011, and You

To use TypeScript you need a definition file and for CRM 2011 you can find it

CRM 2011 TypeScript extension



Hopefully I will get a bit time to have a play with TypeScript myself, I love the idea of it and think it could a great tool to write JavasScript which would be easier to understand/maintain and with the improvements with intellisense would make less sytnax, complete waste of time type mistakes, which could save a bunch of wasted time publishing Javascript files.

This was my first look at TypeScript and the next step is to get my hands dirty and dive in.

If anyone else has any experience using TypeScript please leave a link to your experiences/blog post in the comments

7 thoughts on “What is TypeScript and how does it work with CRM 2011/2013

  1. David Berry December 17, 2014 / 5:09 pm

    Hosk! Thanks for the mentions! Here’s a TypeScript Definition file you might find to your liking, as it’s the one I’m using with every project these days: https://github.com/6ix4our/DefinitelyTyped/tree/master/xrm

    As you can see, I’m trying to get it folded into the DefinitelyTyped project, but they won’t accept it without a “tests” file to accompany it. I’ve been busy enough with project work, that I might not get around to that until January, but if you want to pitch in, you’re more than welcome!


  2. Mixcraft 7 Full Version February 28, 2016 / 10:23 am

    hi!,I love your wrkting very much! percentage we keep up a correspondence extra about your article on AOL?
    I need aan expert on thi area too solve my problem. May be that is you!
    Looking ahead to look you.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s