One thing that has always bothered me is how difficult it is to manage data structure contracts (read: types), throughout a large amount of code. To achieve application-level fidelity, you need a specialized library, that calls for specialized object factories—breaking away from all native syntax, and making useful documentation generation and structure a miserable chore. At least, that’s what it’s been for me.
The question, for me, has always been about bridging the gap: how do I posit stronger typing into my development, if not the language? At first, I was drunk with prototypes and closures, and tried to produce my own typing/inheritance model. Its quirks and desperate lack of syntactic approximation to stronger-typed languages left me to abandon it for something else.
- Definition file for the XrmServiceToolkit project:
(you might have to get it from the Source: Scripts\typescript\XrmServiceToolkit.d.ts)
I use these two together often, coupled with internal definition files for jQuery, JSON, and other common libraries. The stock definition files have done a great job, so these are the only two new ones that I’ve needed, so far. (Though, now that I’m getting into KendoUI, I’d love to see definition files for it.)
- Types! (If that wasn’t the first thing on this list, I should be soundly questioned.)
- 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.)
- Generics! (…coming in TypeScript 0.9)
So, if you want to start learning TypeScript, the best way to start is to do the following:
- (Optionally) Read the TypeScript language specification (but then, I’m into things like that)
- Install the TypeScript plugin for Visual Studio (build support)
- Install the Web Essentials add-in for Visual Studio (IntelliSense support—very basic, currently, but will identify errors at design-time)
- Follow the Quick Start guide for TypeScript (to learn syntax basics)
I find the following tweaks to Visual Studio’s options handy:
- Text Editor\TypeScript\Project: Uncheck all “Compile on Save” options; These collide with Web Essentials, and I prefer to use the “Build” action anyway.
- Web Essentials\TypeScript
- “Compile to EcmaScript 3”: False
- “Add generated files to project”: True
- “Compile all TypeScript files on build”: True
- “Compile TypeScript on save”: False (But, if you want to, use this option, instead of the one from the TypeScript plugin—for now.)
- “Show preview window”: False (This one just gets in my way, and is only really useful if you set the “compile on save” option.)
Then, you can use reference tags in your own TypeScript files, to include the definition files from above and start enjoying TypeScript in CRM 2011 development:
/// <reference path="definitions/Xrm2011.d.ts" />
/// <reference path="definitions/XrmServiceToolkit.d.ts" />