typescript

Business Rules and real time workflows have reduced the necessity to write Javascript in Microsoft CRM for really simple use cases. Once the requirements are a bit more complex and client side scripting seems the right choice, you can try using TypeScript.

Since the dependant files are always included via the triple slash reference comment on all the “.form.ts” files, TypeScript compiler will package up the output Javascript file with all the required dependencies.

There is also a gulp watch in the build task, so that any changes you make to the TypeScript files, triggers the build task and hence the compiled Javascript files will always be in sync with the TypeScript files. In order to start build, just type “gulp” in the command prompt from the folder containing the gulp.babel.js and the default task should take care of the rest.

TypeScript Definitions

Dave Berry has published the tsd files for CRM Client side development. There are so many good reasons to use TypeScript, and Intellisense is one of the top items in my list. There are community published tsds for other popular libraries and so you are not losing any thing by switching to TypeScript.

Head to the TypeScript playground to quickly familiarise yourself with the features and see how your TypeScript code is compiled into Javascript. Here is a quick comparison on couple of the common ones, in terms of CRM development with Dave Berry’s tsd files.

Types is a polarizing topic. Some prefer dynamically typed language, while some prefer strongly typed. With ever increasing Javascript adoption, there is a growing opinion that types are a good thing. TypeScript still compiles into Javascript, but uses typing to improve developer productivity. It also adds some additional features that are not in Javascript. These are some of the advantages:

Intellisense

Compilation stage catches the obvious errors arising due to types

Generics

Modules (available in ES6 as well)

Classes (available in ES6 as well)

Union Types

Microsoft product – great tooling support with VSCode and Visual Studio