Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Their example without `: number` still exhibits the exact same behaviour.

The `: number` isn't a cast either, it's declaring the type of the variable.

You can't help but explicitly name the type of a variable in many cases. What if they were passing val to a function as an argument? You can't have 'function foo(x)', you have to have 'function foo(x: number)' and name the type.

So yes, their example is contrived, but no, what you said is not sound. It has the same problem as the one the author mentions. The typescript compiler intentionally does not catch their issue.

If I'm misunderstanding what you're trying to demonstrate, please make a typescript playground of it.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: