Type checking when code is running

I am using TypeScript on Node.js. TypeScript checks types during compilation, but JavaScript code after compiling is not checking types. For example, this code throws an error:

var test : number;
test = 'test';

But this code on Express will work normally:

app.post('/', function(req, res, next) {
    var test : number;
    test = req.body.test;

As a result, I have test with string type, although test was a number. How can I avoid this problem? How do I check the type of variables when code is running?


How do I check the type of variables when code is running

Basically TypeScript is inferring the type of req to be any. This means it it as completely not type checked to a large extent.

You can disable this with noImplicitAny option and then TypeScript will flag errors when it cannot determine the type of a variable. That would make your code sample a compile time error.

Need Your Help

Code jumps back to button from previous form

vb.net winforms visual-studio-2012

This is driving me crazy. I am calling a form from a button_click on a menu screen. Midway through the form_load on Form2, it is re-calling the button_click from the menu screen and not completin...

Grails and PermGen issue with g:link and g:render

java grails jvm

I've been running grails for sometime without any issues but recently after an upgrade to Grails 1.1.1, I've encountered the dreaded PermGen errors. Prior to the upgrade, no such issue.