If I create a generic class
class Generic<T> {
prop: T;
}
It won't allow me to type something without specifying T in the type
// Generic type 'Generic<T>' requires 1 type argument(s).
const val: Generic = new Generic();
But if I use type inference, it doesn't complain, it lets me instantiate it
const val = new Generic();
// field prop is not of type any, we can't access any properties on it
// val.prop.anything -> Compiler error
// val.prop.toString() -> No error, is it a string?
// val.prop.length -> Compiler error, not a string, just assumes that everything has a toString (based on boxing)
Is this behavior specified? What is the reasoning behind this?
Background
Angular2 has an EventEmitter which requires a type of the argument for the event. However, for some events, you don't pass any arguments, in which case we had been using EventEmitter<void>. However, I just noticed that you can just define emitters without specifying type and new EventEmitter() works. The drawback of this approach is that the compiler won't complain if you pass an argument to emitter.emit('something'). This is not what I'm interested in, just background so readers can understand where the question came from.
new Generic()line is allowed since you might use exactly this line in Javascript that imports a transpiled library. In short: for compatibility to Javascript.Generic type 'Generic<T>' requires 1 type argument(s).propto be something if you want to use it?