<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Derik Whittaker : JavaScript</title><link>http://devlicio.us/blogs/derik_whittaker/archive/tags/JavaScript/default.aspx</link><description>Tags: JavaScript</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Putting the Dynamic back into TypeScript</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2013/05/08/putting-the-dynamic-back-into-typescript.aspx</link><pubDate>Wed, 08 May 2013 10:56:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:111132</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=111132</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=111132</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2013/05/08/putting-the-dynamic-back-into-typescript.aspx#comments</comments><description>&lt;p&gt;One of the really powerful features that TypeScript brings to the JavaScript world is some Static Typing, even if it is only at code/compile time.&amp;#160; With TypeScript I can say that an object is of a certain type which implies there are only a limited set of properties/methods available to me.&amp;#160; This is great, but it does limit the core power of JavaScript and dynamic languages in general.&lt;/p&gt;  &lt;p&gt;Given the static nature of TypeScript, (yes I can choose to ignore this feature, but why?) which I want in most cases, the following will cause me compile time issues.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_27C9A2C5.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_393C944E.png" width="363" height="124" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The reason this is causing me issues is because MemberInitContext does NOT contain a LoadChoachingStaffStats property, but I know that the caller may provide an object which does contain this object.&amp;#160;&amp;#160; Below is my definition for MemberInitContext.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_34C61387.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_1B5E104D.png" width="345" height="150" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Given I know this property MAY be provided at runtime I have a decision to make.&amp;#160; I can do any of the following to resolve my build errors.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add the property to the MemberInitContext &lt;/li&gt;    &lt;li&gt;Create a inherited type which contains this property &lt;/li&gt;    &lt;li&gt;Change my constructor to take an ‘any’ rather than a type &lt;/li&gt;    &lt;li&gt;Add the dynamic back into TypeScript &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I am going to choose the last option here, but how?&amp;#160; Simple, by redefining the variable to an any INSIDE my constructor as below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_48DF3010.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_5D647F8E.png" width="367" height="133" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;By declaring my type as an ‘any’ TypeScript is happy and lets me hack away and complete my tasks.&lt;/p&gt;  &lt;p&gt;Long story shot is that even though TypeScript tries to impose Static typing, which is AWESOME in most cases, you can still force it back to dynamic if you want.&lt;/p&gt;  &lt;p&gt;Till Next Time,&lt;/p&gt;  &lt;p&gt;P.S. Check out my &lt;a href="http://pluralsight.com/training/Courses/TableOfContents/html-for-xaml-developers"&gt;HTML for the XAML developer&lt;/a&gt; course on &lt;a href="http://pluralsight.com/training"&gt;Pluralsight&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=111132" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Typescript/default.aspx">Typescript</category></item><item><title>Inheritance issue w/ Typescript (JavaScript) and MVC Bundling Ordering</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2013/04/30/inheritance-issue-w-typescript-and-mvc-bundling-ordering.aspx</link><pubDate>Tue, 30 Apr 2013 13:08:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:111125</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=111125</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=111125</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2013/04/30/inheritance-issue-w-typescript-and-mvc-bundling-ordering.aspx#comments</comments><description>&lt;p&gt;Today I extended one of our classes to use inheritance via Typescript (love that).&amp;nbsp; When I refreshed the page I received an error here&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_4DA86122.png"&gt;&lt;img height="123" width="405" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_2CB77F2C.png" alt="image" border="0" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" title="image" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;When I dropped to the Chrome debugger and outputted both the values for both &amp;lsquo;d&amp;rsquo; and &amp;lsquo;b&amp;rsquo; I was a bit shocked.&amp;nbsp; &amp;lsquo;d&amp;rsquo; was valid, but &amp;lsquo;b&amp;rsquo; was undefined.&amp;nbsp; I tried a whole slew of things but nothing came to mind.&amp;nbsp; Of course I thought maybe I was using inheritance wrong, but my syntax was right.&lt;/p&gt;
&lt;p&gt;After some digging online I found this &lt;a href="http://typescript.codeplex.com/workitem/627"&gt;link&lt;/a&gt; which talks about how a parent class has to be loaded prior to it child for everything to work.&amp;nbsp; This makes perfect sense given the way JavaScript parses code.&amp;nbsp; I had this brilliant idea that I would simply add a _ prefix to my base class name and that would have the file loaded first.&amp;nbsp; WRONG&amp;hellip; &lt;/p&gt;
&lt;p&gt;If you look at the image below you can see that _BaseViewModel.js is way at the bottom of the list and my error was being thrown in the AthleteListingViewModel&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_680AE4EA.png"&gt;&lt;img height="160" width="606" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_03433DEC.png" alt="image" border="0" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" title="image" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Somehow I needed to force the bundler to load the files in the order I wanted.&amp;nbsp; In our case I am NOT including each file into the bundle manually, rather I am using the &amp;lsquo;IncludeDirectory&amp;rsquo; feature.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;After a bit more searching I found this &lt;a href="http://havethunk.wordpress.com/2013/04/22/javascript-dependency-order-and-asp-net-mvc-bundles/"&gt;link&lt;/a&gt; which solved the same basic problem but in a much more complex way than I needed.&amp;nbsp; However it showed me how I could solve the problem in a few lines of code.&amp;nbsp; What I needed to do was create a new instance of IBundleOrderer and use it.&lt;/p&gt;
&lt;p&gt;This code is my AlphaSortedBundleOrderer which solved my issues.&lt;/p&gt;
&lt;pre name="code" style="display:none;" class="C#"&gt;public class AlphaSortedBundleOrderer : IBundleOrderer
{
    public IEnumerable OrderFiles(BundleContext context, IEnumerable files)
    {
        var sortedFiles = files.OrderBy(x =&amp;gt; x.Name).ToList();

        return sortedFiles;
    }
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt; After I created my new AlphaSortedBundleOrdered I just needed to use it in my bundler.&amp;nbsp; I did this as you see below.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_708E4434.png"&gt;&lt;img height="101" width="530" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_12E5D9AE.png" alt="image" border="0" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;display:inline;" title="image" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Once I had my bundler setup correctly I re-ran the page and my .js files were ordered as expected.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_725E99FB.png"&gt;&lt;img height="96" width="515" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_3DE579C6.png" alt="image" border="0" style="border-top:0px;border-right:0px;border-bottom:0px;border-left:0px;display:inline;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now I am sure there is a 100 ways to solve this problem, but this worked for me.&lt;/p&gt;
&lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=111125" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/.Net/default.aspx">.Net</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/ASP.Net+MVC/default.aspx">ASP.Net MVC</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Typescript/default.aspx">Typescript</category></item><item><title>Validating all observables w/ Knockout validation and Typescript</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2013/04/21/validating-all-observables-w-knockout-validation-and-typescript.aspx</link><pubDate>Sun, 21 Apr 2013 10:52:11 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:110672</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=110672</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=110672</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2013/04/21/validating-all-observables-w-knockout-validation-and-typescript.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://knockoutjs.com"&gt;Knockout&lt;/a&gt; js is an awesome MVVM framework for HTML/Javascript development and there is an extension library which performs data validation called &lt;a href="https://github.com/Knockout-Contrib/Knockout-Validation/wiki"&gt;Knockout.Validation&lt;/a&gt; which is an equally awesome library.&amp;#160; Today when doing some coding I needed to validate that all properties on a VM were valid. A quick search showed me this was very easy and should just work.&amp;#160; However, I am using Typescript and for all of its awesomeness it sometimes makes life a bit more challenging than expected.&lt;/p&gt;  &lt;p&gt;To validate an entire observable all you should need to do is first tell the validation library that your vm is under validation by doing&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_76EF51D5.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_07F6106A.png" width="383" height="66" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;and then you can simply call a .isValid() on your VM as such.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_1C7B5FE8.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_25D7251C.png" width="330" height="61" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;However, when doing this in Typescript I was getting the red squiggly as you see here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_3E66C26C.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_39F041A5.png" width="306" height="48" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;At first I was not sure why, so I decided to take a peek at the source for the validation and I came across the code you see below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_3579C0DE.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_391A6C6C.png" width="644" height="416" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;As you can see, the highlighted yellow is where the .isValid() method is being added to object (obj == your passed in viiew model) so I KNOW that my view model has a .isValid.&amp;#160; Sure enough at runtime if I hit a breakpoint and did this.isValid() i would get the response I was expecting.&amp;#160; However, because .isValid() was being added to my VM dynamically (this is the amazing power of JavaScript) Typescript did not know about the method and it was causing compile time errors.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;How to fix this?&lt;/p&gt;  &lt;p&gt;The simple solution that I found was to ‘fake’ Typescript into thinking that the .isValid computed is on my VM from the start.&amp;#160; I did this by adding the following to my VM&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_33CE166C.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_3361E377.png" width="352" height="39" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you will notice that I am simply declaring the computed I am NO assigning it and that is ok.&amp;#160; In fact if you look at the generated output from the Typescript compiler you will NOT see a computed created for .isValid().&amp;#160; But this does not matter.&amp;#160; The Typescript compiler thinks it is there so you are free to use it off of your VM as you see here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_1C7B5FE8.png"&gt;&lt;img title="image" style="border-left-width:0px;border-right-width:0px;border-bottom-width:0px;display:inline;border-top-width:0px;" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_25D7251C.png" width="330" height="61" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After adding my declaration for isValid() I was good to go and my code worked as expected both at code time and run time.&lt;/p&gt;  &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=110672" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Typescript/default.aspx">Typescript</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Knockout.js/default.aspx">Knockout.js</category></item><item><title>Setting up Unit Testing w/ Jasmine, Chutzpah and Typescript</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2012/12/23/setting-up-unit-testing-w-jasmine-chutzpah-and-typescript.aspx</link><pubDate>Sun, 23 Dec 2012 12:49:46 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:70731</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=70731</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=70731</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2012/12/23/setting-up-unit-testing-w-jasmine-chutzpah-and-typescript.aspx#comments</comments><description>&lt;p&gt;Recently I got back into writing html/javascript code as part of my day job and boy-o-boy have things changed since the last time i did any of this.&amp;#160; One thing that has not changed for me however was my belief in unit testing, so it was very painful for me to be writing hundreds of lines of javascript (ok really &lt;a&gt;TypeScript&lt;/a&gt;) code with NO tests supporting them.&amp;#160; At first I was able to live with this feeling because I was too busy trying to relearn how to do javascript development.&amp;#160; However, I have not reached a comfort level where the lack of tests is killing me again.&lt;/p&gt;  &lt;p&gt;No of course in client/server land of .Net development getting started testing is dead simple, however in the Javascript/html world things are still in the toddler stage, IMO, and there are many, many options to testing and I had no idea which is the best.&amp;#160; After doing some searching and asking on twitter I settled on Jasmine as my test runner.&amp;#160; &lt;/p&gt;  &lt;p&gt;Now that I picked Jasmine, how did I get started?&amp;#160; Here is what I did (this post is a merging of many, many posts I looked at to get me pointed in the right direction)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Step 1: Create a new test project&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Open up Visual Studio 2012 and create a basic MVC 4 application (empty)      &lt;br /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;Step 2: Get &lt;/strong&gt;&lt;a href="http://pivotal.github.com/jasmine/"&gt;&lt;strong&gt;Jasmine&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Install the Jasmine NuGet Package      &lt;br /&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_28E3288F.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_4CBBDA1C.png" width="751" height="99" /&gt;&lt;/a&gt;       &lt;br /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;Step 3: Run your application in order to validate that jasmine is running correctly&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_5302B0AA.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_3CCC9558.png" width="448" height="309" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;Yup, we are good      &lt;br /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;Step 4: Get &lt;/strong&gt;&lt;a href="http://chutzpah.codeplex.com/"&gt;&lt;strong&gt;Chutzpah&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;I wanted a way to run my tests inside of Visual Studio and this plugin seemed to do the trick. I opted to install the test adapter which can be found &lt;a href="http://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe"&gt;here&lt;/a&gt;       &lt;br /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;Step 5: Validate that Chutzpah adapter was setup correctly&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_69E18226.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_572C886F.png" width="562" height="170" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;As you can see from above, it is setup correctly.&lt;/p&gt;    &lt;p&gt;Now I wanted to be able to author my tests in Typescript and have them run as well.      &lt;br /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;Step 6: Download the Jasmine &lt;/strong&gt;&lt;a href="https://github.com/borisyankov/DefinitelyTyped/tree/master/jasmine"&gt;&lt;strong&gt;typescript definition file&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&amp;#160; I put this inside my scripts folder as seen below&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_1A9489D2.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_27FA9CD8.png" width="245" height="101" /&gt;&lt;/a&gt;       &lt;br /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;strong&gt;Step 7: Create my Test Spec&lt;/strong&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The trick to getting this to work of course is that I need to include the jasmine-1.2.d.ts definition file inside my .ts file as below&lt;/p&gt;    &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_206F2D6B.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_2002FA76.png" width="345" height="28" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;I also need to reference my class under test file inside my .ts file as below&lt;/p&gt;    &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_389297C6.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_5EF47B11.png" width="289" height="39" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;Once I did both of these I could write my first test as below&lt;/p&gt;    &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_05565E5D.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/derik_5F00_whittaker/image_5F00_thumb_5F00_44B411ED.png" width="322" height="175" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Bam, now I have a jasmine test written via Typescript and runnable via the Chutzpah test running.&amp;#160; Of course I am sure there are other ways to get this to work, this is just what worked for me.&lt;/p&gt;  &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=70731" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Typescript/default.aspx">Typescript</category></item><item><title>How to compile all your TypeScript .ts files into a Single .js file</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2012/12/08/how-to-compile-all-your-typescript-ts-files-into-a-single-js-file.aspx</link><pubDate>Sat, 08 Dec 2012 15:00:16 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:70569</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=70569</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=70569</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2012/12/08/how-to-compile-all-your-typescript-ts-files-into-a-single-js-file.aspx#comments</comments><description>&lt;p&gt;Recently our team has been using &lt;a&gt;TypeScript&lt;/a&gt; for all our Javascript work.&amp;#160; To be honest it has been a complete pleasure as it ‘just works’.&amp;#160; However one annoyance we quickly found was that we had to choose what was the best approach for using TypeScript.&amp;#160; Do we have a single .ts file which compiles down to a single .js file or do we have multiple .ts files which each compile down to their own .js file.&amp;#160; There are clearly pros/cons to both approaches&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;Single .ts file pros/cons&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Means keeping all our javascript in a single place, making it a bit easier to find/update &lt;/li&gt;    &lt;li&gt;Means that we only need to reference on .js file in our bundles &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Means that our .ts file could become very large and unmanageable over time &lt;/li&gt;    &lt;li&gt;Means that we are increasing our risk of merge issues when we commit it to git &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;&lt;strong&gt;Multiple .ts files pros/cons&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Means we have smaller files to work w/ which should allow for better manageability&lt;/li&gt;    &lt;li&gt;Means we could include a given .js file in a view if we so chose&lt;/li&gt;    &lt;li&gt;Means we could reduce our .js file size for downloads if we so chose&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Means we have multiple .js files which need to be references in our bundles&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;After weighing the pros/cons of each we decided the we better liked the idea of having multiple .ts files, but we also wanted a single .js output file.&amp;#160; Yea we want our cake and be able to eat it to.&lt;/p&gt;  &lt;p&gt;The good news is that this is 100% percent doable.&amp;#160; One of my kick ass devs on our team spent a bit of time working on this problem (read that as THIS IS NOT MY DISCOVERARY) and found a solution.&lt;/p&gt;  &lt;p&gt;The trick was finding out that the command line tool for compiling .ts files has an –out options.&amp;#160; Below is what he did to get this to work&lt;/p&gt;  &lt;h4&gt;&amp;#160;&lt;strong&gt;Step 1: setup the correct content type&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;Open up your .csproj file and look for all references to your .ts files.&amp;#160; They should look something like below&lt;/p&gt;  &lt;p&gt;&amp;lt;Content Include=&amp;quot;ViewModels\Authentication\LoginViewModel.ts&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;You will want to change the type from ‘Content’ to ‘TypeScriptCompile’ as below&lt;/p&gt;  &lt;p&gt;&amp;lt;TypeScriptCompile Include=&amp;quot;ViewModels\Authentication\LoginViewModel.ts&amp;quot; /&amp;gt;   &lt;br /&gt;&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt; Step 2: Add the property group below to your .csproj file&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;&amp;lt;PropertyGroup Condition=&amp;quot;&amp;#39;$(Configuration)&amp;#39; == &amp;#39;Debug&amp;#39;&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160; &amp;lt;TypeScriptSourceMap&amp;gt; --sourcemap&amp;lt;/TypeScriptSourceMap&amp;gt;     &lt;br /&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/p&gt;  &lt;p&gt;You will want to add this towards the top of the .csproj file&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;Step 3: Add a Before Build Step to your .csproj file&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;Open your .cspoj file and add the block below to the bottom of your file&lt;/p&gt;  &lt;p&gt;&amp;lt;Target Name=&amp;quot;BeforeBuild&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160; &amp;lt;Message Text=&amp;quot;Compiling TypeScript files - $(TypeScriptSourceMap)&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;Message Text=&amp;quot;Executing tsc$(TypeScriptSourceMap) @(TypeScriptCompile -&amp;gt;&amp;#39;&amp;amp;quot;%(fullpath)&amp;amp;quot;&amp;#39;, &amp;#39; &amp;#39;)&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;#160; &amp;lt;Exec Command=&amp;quot;tsc$(TypeScriptSourceMap) @(TypeScriptCompile -&amp;gt;&amp;#39;&amp;amp;quot;%(fullpath)&amp;amp;quot;&amp;#39;, &amp;#39; &amp;#39;) --out Scripts/MySingleFile.js&amp;quot; /&amp;gt;     &lt;br /&gt;&amp;lt;/Target&amp;gt;&lt;/p&gt;  &lt;p&gt;You will want to change the path in the Exec command.&amp;#160; I have mine set to Scripts/MySingleFile.js, you may have a different need&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;Step 4: Add this .js file to your MVC Bundles&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;bundles.Add(new ScriptBundle(&amp;quot;~/bundles/projects&amp;quot;).Include(   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;~/Scripts/MySingleFile.js&amp;quot;));&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;Step 5: Include the new bundle in your view&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;@Scripts.Render(&amp;quot;~/bundles/projects&amp;quot;)&lt;/p&gt;  &lt;p&gt;The only issue we have found so far is that unless you use the TypeScript project template you will have to manually switch your Content type for all .ts files each time you add a new one.&amp;#160; This is a PITA but i am sure there is a solution for this to but we have not spent the time or energy to solve it.&lt;/p&gt;  &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=70569" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/ASP.Net+MVC/default.aspx">ASP.Net MVC</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Typescript/default.aspx">Typescript</category></item></channel></rss>