Blogroll

Search

Running TypeScript inside PowerShell with PowerShellJS

April 17th, 2014 by Karl

In my previous post I introduced PowerShellJS where you can run JavaScript within PowerShell. Now that TypeScript 1.0 has dropped, i’ve added initial support to Compile and run TypeScript inside Javascript engine instances from Powershell with PowerShellJS.

So lets look at an example, to see it in action

ipmo PowerShellJS
Invoke-TypeScript -script "1+1"

Here we can simply load PowerShellJS then pass in an expression. Of course the above example could be lying since its valid JS as well, but its not.

#Create a Javascript Engine session we can reuse for multiple commands.
$null = New-JSSession -Name test
Invoke-TypeScript -name test -script "var adder = x => x * x" -NoResults
Invoke-JS -name test -Script "adder(5)"

Here we create a session, and pass in some code that is NOT valid Javascript but definitely TypeScript, and hey look it works. Also note in the second call we are calling Invoke-JS.. within a Session you can mix and match invoke-JS and invoke-TypeScript as you like. In the second call there was no need to have the compilation overhead of TypeScript since it was just simple JavaScript.

There is much more to come, such as dealing with TypeScript compilation errors, doing compile only, and parsing, dealing with AMD modules and the whole enchilada.

Posted in Powershell, PowerShellJS, TypeScript | No Comments »

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.