jshint/jshint — Issue #320: Type Confusion option
Author: goatslacker
Created: 2011-10-27 17:54:01+00:00
State: open

Would be nice to have.

JSLint description (from jslint.com/lint.html)

JSLint can do type inference. It can report cases were variables and properties are used to house multiple types. The warning is Type confusion: {a} and {b}. where the {a} and {b} will be replaced with the names of types.

It is usually easy to see what caused the warning. In some cases, it can be very puzzling. In the puzzling cases, try initializing your vars with typed values. For example, if you expect that n will contain numbers, then write

var n = 0;
That should produce clearer warnings.

Type confusion is not necessarily an error, particularly in a language that provides as much type freedom as this one does. But some inconsistencies are errors, so type discipline might be something to consider adding to your programming style. Also, the fastest JavaScript engines will slow down in the presence of type confusion. To turn off these warnings, turn on the Tolerate type confusion option.