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

First example: you're confusing the annotation for a cast, but it isn't; it won't work the other way around. What you're seeing there is array covariance, an unsound (i.e. broken) subtyping rule for mutable arrays. C# has it too but they've got the decency to check it at runtime.

Second example: that's the point. If the compiler can't prove that x will be initalised before the call it should reject the code until you make it x: number|undefined, to force the closure to handle the undefined case.



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

Search: