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

Nothing in Javascript can ever be completely type safe right now. For example, you compile your TS code and it compiles without error, but you pull a JSON object from the server and pass it into a function which is expecting the argument to implement a certain interface. The problem is the interface is dropped in compilation and there's no type checking at run-time, so there's no way for Typescript to know that the program will be type safe at run-time.


Not sure about TS, but a good type system would not mean you know the structure of dynamic JSON. It would just guarantee that before accessing some field, you would define in some way your code path what to do in case there is that field and in case there isn't. So, at the end, even if you missed the structure, you would have a clearly-defined error reporting logic (or whatever is necessary) at your runtime.


That's one of my bigger niggles as well... You can use json schema for your schema checking though.




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

Search: