Sunday, October 7, 2012

Typescript is neat

javascript is not picky about line endings.  Following code looks fine but causes trouble.

   1: function func() {
   2:     return 
   3:     {
   4:         greet: "Hello World"
   5:     };
   6: }
   7: console.log(func().greet);

Line number 7 prints, undefined.  This is because return statement at line number 2 has line ending.  Now if you use the first code snipped in typescript, you can avoid this error.  Typescript marks the usage of greet in line number 7 as an error.



   1: Error    1    Expected var, class, interface, or module   …\TypeScript1\TypeScript1\app.ts    7    13    app.ts

May be they can do better with the error message. 


This problem can be fixed by moving opening curly brace at line 3 to line 2.



   1: function func() {
   2:     return {
   3:         greet: "Hello World"
   4:     };
   5: }
   6: console.log(func().greet);

Now the error goes away, and also you will get intellisense  for the string property “greet” after func().  in line 6.

Sunday, January 15, 2012

Tips for windows developer working on Mac–Tip # 2

Many times you want to run a text editor from terminal.  May be you want to edit a .bashrc file or a .gitignore file.  I use my favorite editor that works on both windows and mac, Sublime Text

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin

once you typed that command from terminal, you can now open files using sublime directly from your terminal by typing

subl ~/.bashrc

Tips for windows developer working on Mac–Tip # 1

Files/folder with names starting with period are hidden by default in Finder.  So files like .bashrc or .gitignore are not can’t be found.  Running following commands from the terminal fixes that issue

defaults write com.apple.finder AppleShowAllFiles TRUE

killall Finder

Second command restarts the finder.