var x = [1, 'world']; // x: Array<string|number>
I'm not sure I wouldn't prefer this to give an error. var x = [1, 'world']; // x: Array<string|number>
I'm not sure I wouldn't prefer this to give an error.Another example is:
function equal<T>(lhs: T, rhs: T): boolean {
return lhs === rhs;
}
var e = equal(42, 'hello');
Here, there obviously is a type for `T`: `any` (the toplevel dynamic type) or `number|string`.This problem is caused by the requirement that type inference is "complete", i.e. that it correctly infers types for all programs that have a valid typing (i.e. that would work if the programmer specified all types).
Note: This is just my thinking, I don't know if it's the actual reason
Javascript and Coffeescript try to solve this in different ways, most people think that JavaScript's method sucks, and many are not fond of CoffeeScript's non-locality. Personally, I think that demanding variable declaration is still the best option (possibly except for interactive sessions).