Monday, May 23, 2016

Type safety in TypeScript!

As promised, two coworkers gave me and braindump of their Visual Studio Live experience. I have a lot of notes and I'll probably type them up and give you a blog post on it all this weekend. In the short term, here is a teaser. This blob of JavaScript...

function Welcome(x) {
   return "Hello, " + x;
}

 
 

...may be written like so in TypeScript to ensure that a string is handed in for x which is what would make sense.

function Welcome(x: string) {
   return "Hello, " + x;
}

No comments:

Post a Comment