TS1153: let declarations are only available when targeting ECMAScript 6

Are you using trying out Typescript for the first time and getting the error “TS1153: let declarations are only available when targeting ECMAScript 6” when trying to declare variables with the “let” statement?

Well you need to update to a more recent Typescript version – thankfully its very easy (if you have npm installed) 🙂

1) Open command window and type “npm install -g typescript” (without the quotes). This installs latest stable version.
2) Take note of the install directory which is displayed in the command window
3) Open Intellij settings -> Languages & Frameworks -> Typescript -> compiler version
4) Change that to the lib folder of the typescript install directory.

That’s it 😀

Typescript examples – is there any really good ones?

Learning something new is never simple – but really doesn’t help when there seems to be a huge lack of good examples.

Anyone have some proper good examples, feel free to put it into the comments.

What I’m meaning is code examples like the below –

1
2
3
4
5
6
7
var index = 0;
var array = [1, 2, 3];
for( let index = 0; index < array.length; index++ ) {
    console.log( array[index] );
}
 
console.log( index ); //0

Now while there is nothing wrong in the above, for those wishing to learn Typescript and how to do it properly it should really be this –

1
2
3
4
5
6
7
8
9
var index : number = 0;
var array : Array = [1, 2, 3]; 
//This makes array[0] = "bob"; give a Typescript error as you can't put a string into a number type
var arrayLength : number = array.length;
for( let index : number = 0; index < arrayLength; index++ ) {
    console.log( array[index] );
}
 
console.log( index ); //0

See – give those var’s types! its the point of Typescript…
I’ve not even seen good examples on the Typescript site!