It's important to remember that Typescript will never actually change a data type depending on the type information. This understanding comes from the fundamental nature of types: They are there to help you to avoid making mistakes, they don't take an active role in the code.
That being said, Typescript can be as loose or as strict as you like. The stricter it is, the more "helpful" it is to you as a coder (and conversely, the more annoying it can be if you have lazy habits :P)
I would recommend setting a few options in your tsconfig.json, which would have caught your error and you'd have been able to easily see the issue:
"strict": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"noImplicitThis": true,
The result would have been that TypeScript would throw a compile error alerting you to the problem (the problem being that you're passing in the index, not the item):
error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
Incidentally, try to avoid using that old foreach syntax - it's very expensive (calling a function for every item) and can lead to messy code flow.
Try this instead:
for (const item of arr) {
testArgs(item);
}
testArgsat all.testArgs(rec)? Your example fails compilation.