When I define an object like this:
const x: { str: string, num: number } = {
str: str,
num: not_a_num
};
I am surprised to find that even though 'not_a_num' is a string and not a number, the compiler does not throw an error. Instead, it creates an object with two string properties.
Furthermore, I have a function declared as:
store(array: Array<{ str: string, num: number }>): Promise<any> { //... }
But when I pass an array containing the object 'x' as a parameter, typeof(array[0].num) resolves to "string", which is unexpected given my type annotations.
My question is: Why am I not receiving any compiler warnings or errors in these cases? What's the purpose of using type annotations if they don't catch incorrect data types being passed in?
Thank you for your help!