Skip to content

Instantly share code, notes, and snippets.

@jotak
Last active August 29, 2015 14:06
Show Gist options
  • Save jotak/eac2aca66591b3b7cbb2 to your computer and use it in GitHub Desktop.
Save jotak/eac2aca66591b3b7cbb2 to your computer and use it in GitHub Desktop.
Does Typescript make javascript safe? Not so sure about that...
// ...
app.get(libRoot + '/get/:start/:count', function(req, res) {
getSongsPage([/*some data*/], req.params.start, req.params.count);
// ...
});
// ...
function getSongsPage(allSongs: SongInfo[], start: number, count: number): SongInfo[] {
console.log("start=" + start);
console.log("count=" + count);
console.log("start + count=" + (start + count));
console.log("typeof start=" + typeof start);
console.log("typeof count=" + typeof count);
console.log("typeof (start + count)=" + typeof (start + count));
var end: number = Math.min(allSongs.length, start + count);
if (end > start) {
return allSongs.slice(start, end);
}
return [];
}
@jotak
Copy link
Author

jotak commented Sep 27, 2014

See also some nice articles: "Why TypeScript Isn't the Answer" http://www.walkercoderanger.com/blog/2014/02/typescript-isnt-the-answer/ from serie of articles "The JavaScript Minefield"

@bartavelle
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment