Check out the code snippet below:
hello({
name: "Michael"
} as x) // <-- Except missing id here, but it doesn't
type x = {
id: string
name: string
}
function hello(x: any) {
console.log(x)
}
No error is thrown despite using as x
. This is due to type assertion. How can we verify the type without modifying the hello
function?