Skip to content

Instantly share code, notes, and snippets.

@derekpitt
Created April 21, 2015 17:50
Show Gist options
  • Save derekpitt/30d28122f11bfab05dd4 to your computer and use it in GitHub Desktop.
Save derekpitt/30d28122f11bfab05dd4 to your computer and use it in GitHub Desktop.
TypeScript 1.5 alpha in VS2013

These are the steps I had to take to get VS2013 using and outputting TS1.5 with es6 output.

Get Node installed.

npm -g install typescript@1.5.0alpha

This should install to C:\Users\<USER>\AppData\Roaming\npm\node_modules\typescript

Make a copy of C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4 Copy everything from C:\Users\<USER>\AppData\Roaming\npm\node_modules\typescript\bin and paste it over C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4

This is so the build from VS2013 will actually use 1.5alpha

next, use this powershell script:

.\tsUpdate.ps1 -enableDevMode -vsVersion 12 -tsScript C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.4

Ok, VS2013 should now be able to build with ts1.5alpha!

We used this to compile Aurelia es6 code with es6 module support.

if you are using any type definitions that use export = <....> change it to export default <....> the typescript team is still working out es6 modules and all of the definitions out there at microsoft/TypeScript#2242 so this may change.

we have a gulp build that is on our CI server, but for local dev we also had to manually add lib.es6.d.ts to our project to get the build working with es6.

<#
.SYNOPSIS
Run this PowerShell script to enable dev mode and/or a custom script for the TypeScript language service, e.g.
PS C:\> .\scripts\VSDevMode.ps1 -enableDevMode -tsScript C:\src\TypeScript\built\local
Note: If you get security errors, try running powershell as an Administrator and with the "-executionPolicy remoteSigned" switch
.PARAMETER vsVersion
Set to "12" for Dev12 (VS2013) or "14" (the default) for Dev14 (VS2015)
.PARAMETER enableDevMode
Pass this switch to enable attaching a debugger to the language service
.PARAMETER tsScript
The path to a custom language service script to use, e.g. "C:\src\TypeScript\built\local"
#>
Param(
[int]$vsVersion = 14,
[switch]$enableDevMode,
[string]$tsScript
)
$vsRegKey = "HKCU:\Software\Microsoft\VisualStudio\${vsVersion}.0"
$tsRegKey = "${vsRegKey}\TypeScriptLanguageService"
if($enableDevMode -ne $true -and $tsScript -eq ""){
Throw "You must either enable language service debugging (-enableDevMode), set a custom script (-tsScript), or both"
}
if(!(Test-Path $vsRegKey)){
Throw "Visual Studio ${vsVersion} is not installed"
}
if(!(Test-Path $tsRegKey)){
# Create the TypeScript subkey if it doesn't exist
New-Item -path $tsRegKey
}
if($tsScript -ne ""){
$tsScriptServices = "${tsScript}\typescriptServices.js"
$tsScriptlib = "${tsScript}\lib.d.ts"
$tsES6Scriptlib = "${tsScript}\lib.es6.d.ts"
if(!(Test-Path $tsScriptServices)){
Throw "Could not locate the TypeScript language service script at ${tsScriptServices}"
}
else {
$path = resolve-path ${tsScriptServices}
Set-ItemProperty -path $tsRegKey -name CustomTypeScriptServicesFileLocation -value "${path}"
Write-Host "Enabled custom TypeScript language service at ${path} for Dev${vsVersion}"
}
if(!(Test-Path $tsScriptlib)){
Throw "Could not locate the TypeScript default library at ${tsScriptlib}"
}
else {
$path = resolve-path ${tsScriptlib}
Set-ItemProperty -path $tsRegKey -name CustomDefaultLibraryLocation -value "${path}"
Write-Host "Enabled custom TypeScript default library at ${path} for Dev${vsVersion}"
}
if(!(Test-Path $tsES6Scriptlib)){
Throw "Could not locate the TypeScript default ES6 library at ${tsES6Scriptlib}"
}
else {
$path = resolve-path ${tsES6Scriptlib}
Set-ItemProperty -path $tsRegKey -name CustomDefaultES6LibraryLocation -value "${path}"
Write-Host "Enabled custom TypeScript default ES6 library at ${path} for Dev${vsVersion}"
}
}
if($enableDevMode){
Set-ItemProperty -path $tsRegKey -name EnableDevMode -value 1
Write-Host "Enabled developer mode for Dev${vsVersion}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment