Consider this TypeScript code, compiled with 2.6.1:
function foo<T> (bar: T, baz: (T) => void) {
const test: T = bar;
baz(test);
}
const string: string = "a";
foo(string, num => num.parseInt());
I would expect the compilation to fail, because the function foo is called with a string, but the passed callback function is using a method that is not available in string -- while the function signature indicates that type of argument in callback function should be the same as the type of the first parameter.
However, the code compiles and then fails in runtime.
What am I missing?
parseIntin theNumber.prototype.foo<string>(...)foo(string, (num: string) => num.parseInt());